Skip to content

Commit 365448d

Browse files
authored
BUG: Index.isin raising for arrow strings and null set (#55821)
1 parent 407ec33 commit 365448d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/source/whatsnew/v2.1.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Fixed regressions
2222
Bug fixes
2323
~~~~~~~~~
2424
- Bug in :meth:`DatetimeIndex.diff` raising ``TypeError`` (:issue:`55080`)
25-
-
25+
- Bug in :meth:`Index.isin` raising for Arrow backed string and ``None`` value (:issue:`55821`)
2626

2727
.. ---------------------------------------------------------------------------
2828
.. _whatsnew_213.other:

pandas/core/arrays/string_arrow.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
222222
if not len(value_set):
223223
return np.zeros(len(self), dtype=bool)
224224

225-
result = pc.is_in(self._pa_array, value_set=pa.array(value_set))
225+
result = pc.is_in(
226+
self._pa_array, value_set=pa.array(value_set, type=self._pa_array.type)
227+
)
226228
# pyarrow 2.0.0 returned nulls, so we explicily specify dtype to convert nulls
227229
# to False
228230
return np.array(result, dtype=np.bool_)

pandas/tests/indexes/test_base.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas.compat import IS64
1111
from pandas.errors import InvalidIndexError
12-
from pandas.util._test_decorators import async_mark
12+
import pandas.util._test_decorators as td
1313

1414
from pandas.core.dtypes.common import (
1515
is_any_real_numeric_dtype,
@@ -921,6 +921,14 @@ def test_isin_empty(self, empty):
921921
result = index.isin(empty)
922922
tm.assert_numpy_array_equal(expected, result)
923923

924+
@td.skip_if_no("pyarrow")
925+
def test_isin_arrow_string_null(self):
926+
# GH#55821
927+
index = Index(["a", "b"], dtype="string[pyarrow_numpy]")
928+
result = index.isin([None])
929+
expected = np.array([False, False])
930+
tm.assert_numpy_array_equal(result, expected)
931+
924932
@pytest.mark.parametrize(
925933
"values",
926934
[
@@ -1235,7 +1243,7 @@ def test_cached_properties_not_settable(self):
12351243
with pytest.raises(AttributeError, match="Can't set attribute"):
12361244
index.is_unique = False
12371245

1238-
@async_mark()
1246+
@td.async_mark()
12391247
async def test_tab_complete_warning(self, ip):
12401248
# https://github.com/pandas-dev/pandas/issues/16409
12411249
pytest.importorskip("IPython", minversion="6.0.0")

0 commit comments

Comments
 (0)