Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Conflict with DataFrame.where and Interval via data replacement #44181

Closed
3 tasks done
Phil-Garmann opened this issue Oct 25, 2021 · 4 comments · Fixed by #44585
Closed
3 tasks done

BUG: Conflict with DataFrame.where and Interval via data replacement #44181

Phil-Garmann opened this issue Oct 25, 2021 · 4 comments · Fixed by #44585
Labels
Bug Interval Interval data type
Milestone

Comments

@Phil-Garmann
Copy link

Phil-Garmann commented Oct 25, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame([pd.Interval(0,0)])
df.where(df.notnull())

Issue Description

Data replacement using DataFrame.where raises ValueError: Cannot set float NaN to integer-backed IntervalArray,
when the dataframe instance contains one or multiple columns of dtype: interval.

Expected Behavior

Data replacement and dtype conversion as per usual, i.e. in this case no replacement or column dtype conversion should be done, and the original DataFrame should be returned.

expected = df

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1160.15.2.el7.x86_64
Version : #1 SMP Thu Jan 21 16:15:07 EST 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 44.0.0
Cython : None
pytest : 6.2.5
hypothesis : None
show more (open the raw output data in a text editor) ...

tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@Phil-Garmann Phil-Garmann added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 25, 2021
@attack68 attack68 changed the title BUG: BUG: Conflict with DataFrame.where and Interval via data replacement Oct 25, 2021
@jbrockmendel
Copy link
Member

Data replacement and dtype conversion as per usual.

for those of us who don't use 'where' regularly, can you spell out exactly what this would look like?

@Phil-Garmann
Copy link
Author

Using Dataframe.where normally just replaces all elements where the condition (first positional argument cond) is False with whatever is passed to the keyword argument other, defaulting to nan, but could be either a scalar, Series/Datafrane, or callable. This procedure often converts the column dtypes where replacement is happening to object due to the differing types of the elements within the column.

This particular issue is encountered when you want to use the .where approach to e.g. replace nan with None in a concise way, for a Dataframe with multiple columns where one or multiple columns is of dtype: interval.

@jbrockmendel
Copy link
Member

Miscommunication on my part. Can you write out expected = pd.DataFrame(...)

@Phil-Garmann
Copy link
Author

@jbrockmendel I've updated the issue. Simply put, for the given example the original Dataframe, df, is expected as all of its elements are not missing, ie the condition is true for all elements, hence no replacement should be done.

@mroeschke mroeschke added Interval Interval data type and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 30, 2021
@jreback jreback added this to the 1.4 milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Interval Interval data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants