Pandas version checks

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

  • [X] 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

>>> df = pd.DataFrame({'a': [1,2,3, float('nan')], 'b':[float('nan'), 3,3,3]})
>>> df[['a', 'b']].fillna('', inplace=True)
>>> df
     a    b
0  1.0  NaN
1  2.0  3.0
2  3.0  3.0
3  NaN  3.0


>>> df.fillna('', inplace=True)
>>> df
     a    b
0  1.0
1  2.0  3.0
2  3.0  3.0
3       3.0



>>> df = pd.DataFrame({'a': [1,2,3, float('nan')], 'b':[float('nan'), 3,3,3]})
>>> df
     a    b
0  1.0  NaN
1  2.0  3.0
2  3.0  3.0
3  NaN  3.0
>>> df['a'].fillna('', inplace=True)
>>> df
     a    b
0  1.0  NaN
1  2.0  3.0
2  3.0  3.0
3       3.0

Issue Description

[] indexing does not seem to work for DataFrame.fillna when inplace is True. [] indexing seems to work for Series.fillna when inplace is True

Expected Behavior

df = pd.DataFrame({'a': [1,2,3, float('nan')], 'b':[float('nan'), 3,3,3]}) df[['a', 'b']].fillna('', inplace=True) df a b 0 1.0 1 2.0 3.0 2 3.0 3.0 3 3.0

Installed Versions

>>> pd.show_versions() INSTALLED VERSIONS ------------------ commit : 91111fd99898d9dcaa6bf6bedb662db4108da6e6 python : 3.8.10.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : Swedish_Sweden.1252 pandas : 1.5.1 numpy : 1.20.3 pytz : 2021.1 dateutil : 2.8.1 setuptools : 56.0.0 pip : 22.2.2 Cython : None pytest : 6.2.4 hypothesis : None sphinx : 4.2.0 blosc : None feather : None xlsxwriter : None lxml.etree : 4.6.3 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.1 IPython : 7.25.0 pandas_datareader: None bs4 : 4.10.0 bottleneck : None brotli : None fastparquet : None fsspec : 2021.10.1 gcsfs : None matplotlib : 3.4.2 numba : None numexpr : 2.7.3 odfpy : None openpyxl : 3.0.7 pandas_gbq : None pyarrow : 6.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.7.1 snappy : None sqlalchemy : 1.4.26 tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None

Comment From: phofl

hi, thanks for your report. This behaves as expected. Indexing with [] creates a copy, hence you are not modifying the original object.