From 1d8bbb7a39cdab23a1ea4eeec93de79e56d22489 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Thu, 20 Feb 2025 17:18:47 +0000 Subject: [PATCH] BUG: fix error message for multiindex.fillna (#60974) fix error message for multiindex.fillna --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/indexes/multi.py | 2 +- pandas/tests/base/test_fillna.py | 2 +- pandas/tests/indexes/multi/test_missing.py | 2 +- pandas/tests/indexes/test_old_base.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 090be6dc250ba..999c2ebf32cc9 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -817,6 +817,7 @@ Other - Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`) - Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`) - Bug in :meth:`Index.sort_values` when passing a key function that turns values into tuples, e.g. ``key=natsort.natsort_key``, would raise ``TypeError`` (:issue:`56081`) +- Bug in :meth:`MultiIndex.fillna` error message was referring to ``isna`` instead of ``fillna`` (:issue:`60974`) - Bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`) - Bug in :meth:`Series.dt` methods in :class:`ArrowDtype` that were returning incorrect values. (:issue:`57355`) - Bug in :meth:`Series.isin` raising ``TypeError`` when series is large (>10**6) and ``values`` contains NA (:issue:`60678`) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index dc48cd1ed958e..1cb984b5389d8 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1760,7 +1760,7 @@ def fillna(self, value): """ fillna is not implemented for MultiIndex """ - raise NotImplementedError("isna is not defined for MultiIndex") + raise NotImplementedError("fillna is not defined for MultiIndex") @doc(Index.dropna) def dropna(self, how: AnyAll = "any") -> MultiIndex: diff --git a/pandas/tests/base/test_fillna.py b/pandas/tests/base/test_fillna.py index 7300d3013305a..8c56bcc169d8e 100644 --- a/pandas/tests/base/test_fillna.py +++ b/pandas/tests/base/test_fillna.py @@ -16,7 +16,7 @@ def test_fillna(index_or_series_obj): obj = index_or_series_obj if isinstance(obj, MultiIndex): - msg = "isna is not defined for MultiIndex" + msg = "fillna is not defined for MultiIndex" with pytest.raises(NotImplementedError, match=msg): obj.fillna(0) return diff --git a/pandas/tests/indexes/multi/test_missing.py b/pandas/tests/indexes/multi/test_missing.py index 14ffc42fb4b59..41cfa093ae53c 100644 --- a/pandas/tests/indexes/multi/test_missing.py +++ b/pandas/tests/indexes/multi/test_missing.py @@ -8,7 +8,7 @@ def test_fillna(idx): # GH 11343 - msg = "isna is not defined for MultiIndex" + msg = "fillna is not defined for MultiIndex" with pytest.raises(NotImplementedError, match=msg): idx.fillna(idx[0]) diff --git a/pandas/tests/indexes/test_old_base.py b/pandas/tests/indexes/test_old_base.py index 49609d28ca56e..5f36b8c3f5dbf 100644 --- a/pandas/tests/indexes/test_old_base.py +++ b/pandas/tests/indexes/test_old_base.py @@ -597,7 +597,7 @@ def test_fillna(self, index): pytest.skip(f"Not relevant for Index with {index.dtype}") elif isinstance(index, MultiIndex): idx = index.copy(deep=True) - msg = "isna is not defined for MultiIndex" + msg = "fillna is not defined for MultiIndex" with pytest.raises(NotImplementedError, match=msg): idx.fillna(idx[0]) else: