Description
-
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, theSettingWithCopyWarning
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