You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) ...
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 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.
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
Issue Description
Data replacement using
DataFrame.where
raisesValueError: 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 columndtype
conversion should be done, and the originalDataFrame
should be returned.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
The text was updated successfully, but these errors were encountered: