Skip to content

BUG: AttributeError when using dict downcast in DataFrame.fillna #40809

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
hsorsky opened this issue Apr 6, 2021 · 0 comments · Fixed by #40861
Closed
2 of 3 tasks

BUG: AttributeError when using dict downcast in DataFrame.fillna #40809

hsorsky opened this issue Apr 6, 2021 · 0 comments · Fixed by #40861
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@hsorsky
Copy link

hsorsky commented Apr 6, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import pandas as pd
import numpy as np

X = pd.DataFrame(
    {
        "col1": [1, np.nan]
    }
)

X.fillna({"col1": 2}, downcast={"col1": np.int64})

Problem description

The docs state that supplying downcast as a dict of item -> dtype is acceptable here. I would have thought that this would fill NAs in "col1" with value 2 and then downcasted "col1" to dtype int64. Instead an error is raised.

AttributeError: 'dict' object has no attribute 'type'

Expected Output

   col1
0     1
1     2

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : f2c8480af2f25efdbd803218b9d87980f416563e
python           : 3.7.4.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 19.6.0
Version          : Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : en_US.UTF-8
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.2.3
numpy            : 1.20.1
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 19.0.3
setuptools       : 40.8.0
Cython           : 0.29.22
pytest           : 6.2.2
hypothesis       : None
sphinx           : 3.5.3
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : 2.8.6 (dt dec pq3 ext lo64)
jinja2           : 2.11.3
IPython          : 7.21.0
pandas_datareader: None
bs4              : 4.9.3
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.3.4
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.6.1
sqlalchemy       : None
tables           : None
tabulate         : 0.8.7
xarray           : None
xlrd             : None
xlwt             : None
numba            : 0.53.0

@hsorsky hsorsky added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 6, 2021
@hsorsky hsorsky changed the title BUG: BUG: AttributeError when using dict downcast in DataFrame.fillna Apr 6, 2021
@jreback jreback added 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 Apr 13, 2021
@jreback jreback added this to the 1.3 milestone Apr 13, 2021
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