Skip to content

BUG: fillna downcast object to int even downcast=False/None #45603

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

Closed
2 of 3 tasks
yinweisu opened this issue Jan 24, 2022 · 6 comments · Fixed by #45642
Closed
2 of 3 tasks

BUG: fillna downcast object to int even downcast=False/None #45603

yinweisu opened this issue Jan 24, 2022 · 6 comments · Fixed by #45642
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@yinweisu
Copy link

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

import pandas as pd
df = pd.Series([1,2,3], dtype='object')
df.fillna('', downcast=False)  # will get int64 instead

Issue Description

fillna will convert an object dataframe to int64 dataframe even when downcast is specified to be False or None

Expected Behavior

The dataframe should keep the original dtype

Installed Versions

NSTALLED VERSIONS

commit : bb1f651
python : 3.9.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.0
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 57.4.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 : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@yinweisu yinweisu added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 24, 2022
@phofl
Copy link
Member

phofl commented Jan 25, 2022

This is already known, see #44241

@phofl phofl closed this as completed Jan 25, 2022
@phofl phofl added Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 25, 2022
@jbrockmendel
Copy link
Member

I think downcast=False is separate from #44241

@jbrockmendel jbrockmendel reopened this Jan 25, 2022
@phofl
Copy link
Member

phofl commented Jan 25, 2022

The note inline says:

            # GH#44241 We downcast regardless of the argument;
            #  respecting 'downcast=None' may be worthwhile at some point,
            #  but ATM it breaks too much existing code.
            # split and convert the blocks

So this sounded related to me.

@jbrockmendel
Copy link
Member

definitely related, but not identical. when we did #44241 we were focused on "None" and "infer", and False was an afterthought. IIRC there was only one place where we used downcast=False and it was in the io code so we just changed that, so there are no tests that use it.

@phofl
Copy link
Member

phofl commented Jan 25, 2022

Got you, thx

@jreback jreback added this to the 1.4.1 milestone Jan 27, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Feb 9, 2022
@simonjayhawkins
Copy link
Member

first bad commit: [3bbaa89] BUG: Series[object].fillna ignoring downcast='infer' (#45062)

@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants