Skip to content

Commit

Permalink
Backport PR pandas-dev#55821: BUG: Index.isin raising for arrow strin…
Browse files Browse the repository at this point in the history
…gs and null set
  • Loading branch information
phofl authored and lithomas1 committed Dec 4, 2023
1 parent 0e9ffbe commit c6efdb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
if not len(value_set):
return np.zeros(len(self), dtype=bool)

result = pc.is_in(self._pa_array, value_set=pa.array(value_set))
result = pc.is_in(
self._pa_array, value_set=pa.array(value_set, type=self._pa_array.type)
)
# pyarrow 2.0.0 returned nulls, so we explicily specify dtype to convert nulls
# to False
return np.array(result, dtype=np.bool_)
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pandas.compat import IS64
from pandas.errors import InvalidIndexError
import pandas.util._test_decorators as td

from pandas.core.dtypes.common import (
is_any_real_numeric_dtype,
Expand Down Expand Up @@ -915,6 +916,14 @@ def test_isin_empty(self, empty):
result = index.isin(empty)
tm.assert_numpy_array_equal(expected, result)

@td.skip_if_no("pyarrow")
def test_isin_arrow_string_null(self):
# GH#55821
index = Index(["a", "b"], dtype="string[pyarrow_numpy]")
result = index.isin([None])
expected = np.array([False, False])
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
"values",
[
Expand Down

0 comments on commit c6efdb0

Please sign in to comment.