Skip to content

Commit 2cd832c

Browse files
committed
fix: Series.is_in
1 parent 98cc8bd commit 2cd832c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

narwhals/series.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
is_compliant_series,
1515
is_eager_allowed,
1616
is_index_selector,
17+
iterable_to_sequence,
1718
qualified_type_name,
1819
supports_arrow_c_stream,
1920
)
@@ -25,7 +26,6 @@
2526
from narwhals.series_list import SeriesListNamespace
2627
from narwhals.series_str import SeriesStringNamespace
2728
from narwhals.series_struct import SeriesStructNamespace
28-
from narwhals.translate import to_native
2929
from narwhals.typing import IntoSeriesT
3030

3131
if TYPE_CHECKING:
@@ -948,9 +948,12 @@ def is_in(self, other: Any) -> Self:
948948
]
949949
]
950950
"""
951-
return self._with_compliant(
952-
self._compliant_series.is_in(to_native(other, pass_through=True))
951+
other = (
952+
other.to_native()
953+
if isinstance(other, Series)
954+
else iterable_to_sequence(other, backend=self.implementation)
953955
)
956+
return self._with_compliant(self._compliant_series.is_in(other))
954957

955958
def arg_true(self) -> Self:
956959
"""Find elements where boolean Series is True.

tests/expr_and_series/is_in_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,21 @@ def test_filter_is_in_with_series(constructor_eager: ConstructorEager) -> None:
6767

6868

6969
def test_ser_is_in_iterable(
70-
constructor_eager: ConstructorEager, into_iter_16: IntoIterable
70+
constructor_eager: ConstructorEager,
71+
into_iter_16: IntoIterable,
72+
request: pytest.FixtureRequest,
7173
) -> None:
72-
ser = nw.from_native(constructor_eager(data)).get_column("a")
74+
test_name = request.node.name
75+
# NOTE: This *could* be supported by using `ExtensionArray.tolist` (same path as numpy)
76+
request.applymarker(
77+
pytest.mark.xfail(
78+
("polars" in test_name and "pandas" in test_name and "array" in test_name),
79+
raises=TypeError,
80+
reason="Polars doesn't support `pd.array`.\nhttps://github.com/pola-rs/polars/issues/22757",
81+
)
82+
)
7383
iterable = into_iter_16((4, 2))
84+
ser = nw.from_native(constructor_eager(data)).get_column("a")
7485
result = ser.is_in(iterable)
7586
expected = [False, True, True, False]
7687
assert_equal_series(result, expected, "a")

0 commit comments

Comments
 (0)