Skip to content

BUG: dataframe.fillna not working for dataframe with duplicate column names #43476

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
3 tasks done
Phil-Garmann opened this issue Sep 9, 2021 · 1 comment · Fixed by #43492
Closed
3 tasks done

BUG: dataframe.fillna not working for dataframe with duplicate column names #43476

Phil-Garmann opened this issue Sep 9, 2021 · 1 comment · Fixed by #43492
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@Phil-Garmann
Copy link

  • 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 master branch of pandas.

Reproducible Example

import pandas as pd
df1 = pd.DataFrame(pd.NA, index=[0, 1], columns=['A', 'A', 'B'])
df1.fillna({'A': 0})

df2 = pd.DataFrame(pd.NA, index=[0, 1], columns=['A', 'A'])
df2.fillna({'A': 0})

Issue Description

For dataframes with duplicate column names .fillna fails to fill missing values, if a dict is passed as the value parameter

  • Example 1 (df1). When multiple, but not all, columns share a name, the SettingWithCopyWarning is thrown.
  • Example 2 (df2). When all column names are identical, no error is thrown, nor is missing values replaced.

Expected Behavior

Expecting missing values in columns of the same name to be filled according to the parsed dict.

Installed Versions

INSTALLED VERSIONS

commit : 5f648bf
python : 3.8.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Danish_Denmark.1252
pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.2.3
setuptools : 49.2.1
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.08.1
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None

@Phil-Garmann Phil-Garmann added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 9, 2021
@phofl
Copy link
Member

phofl commented Sep 9, 2021

This is actually raising a SettingWithCopyWarning, probably the reason for this

@jreback jreback added this to the 1.4 milestone Sep 10, 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 Sep 10, 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.

3 participants