Skip to content

Commit c6efdb0

Browse files
phofllithomas1
authored andcommitted
Backport PR pandas-dev#55821: BUG: Index.isin raising for arrow strings and null set
1 parent 0e9ffbe commit c6efdb0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/core/arrays/string_arrow.py

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

218-
result = pc.is_in(self._pa_array, value_set=pa.array(value_set))
218+
result = pc.is_in(
219+
self._pa_array, value_set=pa.array(value_set, type=self._pa_array.type)
220+
)
219221
# pyarrow 2.0.0 returned nulls, so we explicily specify dtype to convert nulls
220222
# to False
221223
return np.array(result, dtype=np.bool_)

pandas/tests/indexes/test_base.py

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from pandas.compat import IS64
1212
from pandas.errors import InvalidIndexError
13+
import pandas.util._test_decorators as td
1314

1415
from pandas.core.dtypes.common import (
1516
is_any_real_numeric_dtype,
@@ -915,6 +916,14 @@ def test_isin_empty(self, empty):
915916
result = index.isin(empty)
916917
tm.assert_numpy_array_equal(expected, result)
917918

919+
@td.skip_if_no("pyarrow")
920+
def test_isin_arrow_string_null(self):
921+
# GH#55821
922+
index = Index(["a", "b"], dtype="string[pyarrow_numpy]")
923+
result = index.isin([None])
924+
expected = np.array([False, False])
925+
tm.assert_numpy_array_equal(result, expected)
926+
918927
@pytest.mark.parametrize(
919928
"values",
920929
[

0 commit comments

Comments
 (0)