Skip to content

BUG: fillna specify duplicated column that is MultiIndex causes RecursionError #53498

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

Open
2 of 3 tasks
yuji38kwmt opened this issue Jun 2, 2023 · 1 comment
Open
2 of 3 tasks
Labels
Bug Error Reporting Incorrect or improved errors from pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex

Comments

@yuji38kwmt
Copy link

Pandas version checks

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

Reproducible Example

import pandas
import numpy

data = [[numpy.nan, 2, 3], [4, numpy.nan, 6], [7, 8, numpy.nan]]
df = pandas.DataFrame(
    data, columns=pandas.MultiIndex.from_tuples([("x", "a"), ("x", "a"), ("y", "b")])
)
df.fillna({("x", "a"): 0})
# RecursionError occurred

Issue Description

I have created a dataframe that contains MultiIndex columns. However, the columns in the dataframe are duplicated.

When I execute the fillna function and specify the duplicated column, a RecursionError occurs.

Expected Behavior

I expected that RecursionError did not occur.

Installed Versions

INSTALLED VERSIONS

commit : 965ceca
python : 3.11.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-72-generic
Version : #79-Ubuntu SMP Wed Apr 19 08:22:18 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : ja_JP.UTF-8
LOCALE : ja_JP.UTF-8

pandas : 2.0.2
numpy : 1.24.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.1.2
Cython : None
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@yuji38kwmt yuji38kwmt added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 2, 2023
@JostBrand
Copy link

I don't think this is a bug and more of a feature request for fillna to support MultiIndex.:

    def fillna(self, value=None, downcast=None):

        """
        fillna is not implemented for MultiIndex
        """

So the question remains why you get a recursion error and not a NotImplementedError. But as the user documentation points out for duplicate labels:

[...] Other methods, like indexing, can give very surprising results.

I know this solution df['x']['a'].fillna(0) is not really satisfying.

@mroeschke mroeschke added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Error Reporting Incorrect or improved errors from pandas MultiIndex and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex
Projects
None yet
Development

No branches or pull requests

3 participants