-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: TypeError when attempting to replace Nullable integer data type with a float value #45729
Comments
I'm working on a pull request designed to solve both this issue and #40472, by enforcing implicit type casting in some instances of calling the |
take |
I don't think we have completely decided on this matter. @jorisvandenbossche has advocated non-casting behavior for I'd suggest weighing in on the discussion in #39584, #24020, #45153, #25288 |
I tested again and can confirm this issue is still present in pandas 1.4.1 as well as current main branch (tested commit afec0e9). pandas 1.4.1 yields the same TypeError as 1.4.0: I realize this is behavior is still under discussion so not sure what the appropriate solution should be at this point. |
I propose closing here to keep the discussion together In the other issues since this is larger than just replace |
Pandas version checks
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 main branch of pandas.
Reproducible Example
Issue Description
When using any of the pandas Nullable integer data types (
Int8Dtype
,Int16Dtype
,Int32Dtype
,Int64Dtype
,UInt8Dtype
,UInt16Dtype
,UInt32Dtype
,UInt64Dtype
) as a dtype for values in a Series or DataFrame, then attempting to replace that value with a float value, the type casting fails under pandas 1.4.0, and also fails under the current main branch with a slightly different TypeError.I wasn't sure whether this was intended behavior at first (possibly designed to encourage explicit type casting instead of implicit). But after further testing I think this is indeed a bug because this TypeError does not occur under pandas 1.3.5. Nor does this TypeError occur when using other integer data types such as standard Python
int
or numpy dtypes likeint32
andint64
. In all those cases, the type casting is done implicitly without error, and the final value is 1.1 of dtypefloat64
.Expected Behavior
The Nullable integer value should be replaced with new value and implicitly be type cast as a float.
Installed Versions
commit : bb1f651
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22000
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.0
numpy : 1.22.1
pytz : 2021.3
dateutil : 2.8.2
pip : 21.1.2
setuptools : 57.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
Suggested Labels
Regression
,replace
,Dtype Conversions
The text was updated successfully, but these errors were encountered: