Skip to content

Commit

Permalink
[skip-ci] wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Feb 12, 2025
1 parent 13b65ad commit 0cfa696
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions narwhals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,9 @@ def is_in(self: Self, other: Any) -> Self:
from narwhals.series import Series

if isinstance(other, Iterable) and not isinstance(other, (str, bytes)):
# In the eager case, `other` is allowed to be a Series. However,
# we don't allow expressiions. So, to avoid special-casing, we
# just call `to_native` here if `other` is a Series.
return self.__class__(
lambda plx: self._to_compliant_expr(plx).is_in(
other.to_native() if isinstance(other, Series) else other
Expand Down
3 changes: 3 additions & 0 deletions narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ def is_in(self: Self, other: Any) -> Self:
]
]
"""
# In the eager case, `other` is allowed to be a Series. However,
# we don't allow expressiions. So, to avoid special-casing, we
# just call `to_native` here if `other` is a Series.
return self._from_compliant_series(
self._compliant_series.is_in(
other.to_native() if isinstance(other, self.__class__) else other
Expand Down
22 changes: 22 additions & 0 deletions tests/expr_and_series/is_between_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Literal

import pytest
from datetime import datetime

import narwhals.stable.v1 as nw
from tests.utils import Constructor
Expand Down Expand Up @@ -30,6 +31,27 @@ def test_is_between(
expected_dict = {"a": expected}
assert_equal_data(result, expected_dict)

@pytest.mark.parametrize(
("closed", "expected"),
[
("left", [False, False]),
("right", [False, True]),
("both", [False, True]),
("none", [False, False]),
],
)
def test_is_between_datetimes(
constructor: Constructor,
closed: Literal["left", "right", "none", "both"],
expected: list[bool],
) -> None:
data = {"a": [datetime(2020,1,1), datetime(2020,6,1)]}
df = nw.from_native(constructor(data))
result = df.select(nw.col("a").is_between(datetime(2020,3,1), datetime(2020,6,1), closed=closed))
expected_dict = {"a": expected}
assert_equal_data(result, expected_dict)



def test_is_between_expressified(constructor: Constructor) -> None:
data = {"a": [1, 4, 2, 5], "b": [0, 5, 2, 4], "c": [9, 9, 9, 9]}
Expand Down

0 comments on commit 0cfa696

Please sign in to comment.