Skip to content

Commit

Permalink
try fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Feb 12, 2025
1 parent 48e5d75 commit 13b65ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
9 changes: 3 additions & 6 deletions narwhals/_arrow/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,9 @@ def tail(self: Self, n: int) -> Self:
return self._from_native_series(ser.slice(abs(n)))

def is_in(self: Self, other: Any) -> Self:
if isinstance(other, list) and isinstance(other[0], self.__class__):
# We can't use `broadcast_and_align` because we don't want to align here.
# `other` is just a sequence that all rows from `self` are checked against.
value_set = other[0]._native_series
else:
value_set = pa.array(other)
value_set = (
other if isinstance(other, pa.ChunkedArray) else pa.chunked_array([other])
)
ser = self._native_series
return self._from_native_series(pc.is_in(ser, value_set=value_set))

Expand Down
4 changes: 0 additions & 4 deletions narwhals/_pandas_like/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@ def is_between(

def is_in(self: Self, other: Any) -> PandasLikeSeries:
ser = self._native_series
if isinstance(other, list) and isinstance(other[0], self.__class__):
# We can't use `broadcast_and_align` because we don't want to align here.
# `other` is just a sequence that all rows from `self` are checked against.
other = other[0]._native_series
res = ser.isin(other)
return self._from_native_series(res)

Expand Down
6 changes: 5 additions & 1 deletion narwhals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,13 @@ def is_in(self: Self, other: Any) -> Self:
| 3 10 False |
└──────────────────┘
"""
from narwhals.series import Series

if isinstance(other, Iterable) and not isinstance(other, (str, bytes)):
return self.__class__(
lambda plx: self._to_compliant_expr(plx).is_in(other),
lambda plx: self._to_compliant_expr(plx).is_in(
other.to_native() if isinstance(other, Series) else other
),
self._metadata,
)
else:
Expand Down
4 changes: 3 additions & 1 deletion narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,9 @@ def is_in(self: Self, other: Any) -> Self:
]
"""
return self._from_compliant_series(
self._compliant_series.is_in(self._extract_native(other))
self._compliant_series.is_in(
other.to_native() if isinstance(other, self.__class__) else other
)
)

def arg_true(self: Self) -> Self:
Expand Down

0 comments on commit 13b65ad

Please sign in to comment.