-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
REGR: replace
casts columns to object
#32988
Comments
I debugged this a bit. The reason seems to be here:
The function tries the replace again after converting the FloatBlock to an ObjectBlock. We could try to convert the ObjectBlock back after executing the replace. I tried this for the example mentioned above and ran the relevant (I hope I ran all relevant :)) tests. I committed the small change here. If this is a desired fix, I would add tests and create a pull request. |
Thanks for looking into this! Unfortunately, I'm not familiar enough with pandas internals to review your changes. |
this was working in 0.25.3 so this is a regression >>> import numpy as np
>>>
>>> import pandas as pd
>>>
>>> pd.__version__
'0.25.3'
>>>
>>> pd.DataFrame(np.eye(2)).replace(to_replace=[None, -np.inf, np.inf], value=np.nan).dtypes
0 float64
1 float64
dtype: object
>>> >>> import numpy as np
>>>
>>> import pandas as pd
>>>
>>> pd.__version__
'1.1.0.dev0+1008.g60b0e9fbc'
>>>
>>> pd.DataFrame(np.eye(2)).replace(to_replace=[None, -np.inf, np.inf], value=np.nan).dtypes
0 object
1 object
dtype: object |
01f90c1 is the first bad commit
|
replace
casts columns to object
replace
casts columns to object
Calling
df.replace
casts columns toobject
Problem description
I'd expect that the dtypes of the columns remain the same after replacing with pd.NA (especially considering no values are replaced in the above call). We do not get this issue if
to_replace
is any subset of[None, -np.inf, np.inf]
. We get the same issue ifvalue
is insteadnp.nan
.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : bed9103
python : 3.7.0.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.26.0.dev0+2701.gbed9103e5
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.1.post20200323
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 : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: