Skip to content

DataFrame.fillna() downcast argument does not work when the value for fillna is a dict instead of a scalar #15277

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
albertvillanova opened this issue Feb 1, 2017 · 0 comments
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@albertvillanova
Copy link
Contributor

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({'a': [1, None]})

df1 = df.fillna(0, downcast='infer')
df2 = df.fillna({'a': 0}, downcast='infer')

print(df1)
print(df2)

Problem description

When using the method DataFrame.fillna(), the downcast option is not working when the value for fillna is a dict instead of a scalar.

Expected Output

In both previous DataFrame examples, the column should be downcasted to integer dtype instead of float.

Output of pd.show_versions()

commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 3.13.0-107-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: ca_ES.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0.post20161106
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: 0.2.1

albertvillanova pushed a commit to albertvillanova/pandas that referenced this issue Feb 1, 2017
@jreback jreback added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Difficulty Novice labels Feb 1, 2017
@jreback jreback added this to the 0.20.0 milestone Feb 1, 2017
albertvillanova pushed a commit to albertvillanova/pandas that referenced this issue Feb 3, 2017
@jreback jreback closed this as completed in f742a66 Feb 6, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#15277

Author: Albert Villanova del Moral <[email protected]>

Closes pandas-dev#15278 from albertvillanova/fix-15277 and squashes the following commits:

1b594a9 [Albert Villanova del Moral] Fix tab indentation
631a2dc [Albert Villanova del Moral] Add whatsnew note
d691954 [Albert Villanova del Moral] BUG: Fix downcast argument for DataFrame.fillna()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants