From 96f85acebe7e5858b937c3f8ed367b9b3b8a4a34 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 17 Dec 2025 11:03:21 -0800 Subject: [PATCH 1/2] BUG: Allow is_bool_indexer to recognize NumpyExtensionArray --- pandas/core/common.py | 4 +++- pandas/tests/indexes/ranges/test_range.py | 6 ++++++ pandas/tests/test_common.py | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pandas/core/common.py b/pandas/core/common.py index b6aab3ddfee63..7b6ba2d9010a7 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -45,6 +45,7 @@ ABCExtensionArray, ABCIndex, ABCMultiIndex, + ABCNumpyExtensionArray, ABCSeries, ) from pandas.core.dtypes.inference import iterable_not_string @@ -128,7 +129,8 @@ def is_bool_indexer(key: Any) -> bool: and convert to an ndarray. """ if isinstance( - key, (ABCSeries, np.ndarray, ABCIndex, ABCExtensionArray) + key, + (ABCSeries, np.ndarray, ABCIndex, ABCExtensionArray, ABCNumpyExtensionArray), ) and not isinstance(key, ABCMultiIndex): if key.dtype == np.object_: key_array = np.asarray(key) diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index 1f9df30d60c11..a7aca7b8dfe47 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -710,6 +710,12 @@ def test_take_return_rangeindex(): tm.assert_index_equal(result, expected, exact=True) +def test__getitem__boolean_numpyextensionarray(): + ri = RangeIndex(1) + result = ri[pd.arrays.NumpyExtensionArray(np.array([True]))] + tm.assert_index_equal(ri, result) + + @pytest.mark.parametrize( "rng, exp_rng", [ diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 9f68ef5ffdc47..d049b89423aab 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -236,6 +236,12 @@ def test_frozenlist(self): expected = df[[]] tm.assert_frame_equal(result, expected) + @pytest.mark.parametrize("scalar", [1, True]) + def test_numpyextensionarray(self, scalar): + # GH 63391 + arr = pd.arrays.NumpyExtensionArray(np.array([scalar])) + assert com.is_bool_indexer(arr) is isinstance(scalar, bool) + @pytest.mark.parametrize("with_exception", [True, False]) def test_temp_setattr(with_exception): From 2255ce4427e2fea9a79a6c82e016aa7b8494b293 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:13:42 -0800 Subject: [PATCH 2/2] Add >1 length mask test --- pandas/tests/indexes/ranges/test_range.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index a7aca7b8dfe47..2cf8febc41671 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -716,6 +716,18 @@ def test__getitem__boolean_numpyextensionarray(): tm.assert_index_equal(ri, result) +@pytest.mark.parametrize( + "container", + [np.array, pd.Series, lambda x: pd.arrays.NumpyExtensionArray(np.array(x))], + ids=["numpy-array", "series", "numpy-extension-array"], +) +def test__getitem__boolean_arraylike(container): + ri = RangeIndex(5) + result = ri[container([True, True, False, False, True])] + expected = Index([0, 1, 4], dtype="int64") + tm.assert_index_equal(result, expected) + + @pytest.mark.parametrize( "rng, exp_rng", [