Skip to content

Commit 8f5d86c

Browse files
committed
MultiIndex: support isna, fixes pandas-dev#34019
1 parent 5468223 commit 8f5d86c

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

pandas/core/dtypes/missing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def _isna(obj, inf_as_na: bool = False):
153153
return libmissing.checknull(obj)
154154
# hack (for now) because MI registers as ndarray
155155
elif isinstance(obj, ABCMultiIndex):
156-
raise NotImplementedError("isna is not defined for MultiIndex")
156+
# If there is within a level an NA, the entire label is considered NA
157+
return obj.to_frame().isna().any(axis="columns").values
157158
elif isinstance(obj, type):
158159
return False
159160
elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndex, ABCExtensionArray)):

pandas/tests/indexes/common.py

-5
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,6 @@ def test_nulls(self, index):
625625
# as these are adequately tested for function elsewhere
626626
if len(index) == 0:
627627
tm.assert_numpy_array_equal(index.isna(), np.array([], dtype=bool))
628-
elif isinstance(index, MultiIndex):
629-
idx = index.copy()
630-
msg = "isna is not defined for MultiIndex"
631-
with pytest.raises(NotImplementedError, match=msg):
632-
idx.isna()
633628
elif not index.hasnans:
634629
tm.assert_numpy_array_equal(index.isna(), np.zeros(len(index), dtype=bool))
635630
tm.assert_numpy_array_equal(index.notna(), np.ones(len(index), dtype=bool))

pandas/tests/indexes/multi/test_missing.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ def test_dropna():
5656
def test_nulls(idx):
5757
# this is really a smoke test for the methods
5858
# as these are adequately tested for function elsewhere
59-
60-
msg = "isna is not defined for MultiIndex"
61-
with pytest.raises(NotImplementedError, match=msg):
62-
idx.isna()
59+
idx.isna()
6360

6461

6562
@pytest.mark.xfail(reason="isna is not defined for MultiIndex")

0 commit comments

Comments
 (0)