diff --git a/narwhals/_arrow/expr.py b/narwhals/_arrow/expr.py index 1c0d0734e..df5c95367 100644 --- a/narwhals/_arrow/expr.py +++ b/narwhals/_arrow/expr.py @@ -283,7 +283,12 @@ def is_null(self: Self) -> Self: def is_nan(self: Self) -> Self: return reuse_series_implementation(self, "is_nan") - def is_between(self: Self, lower_bound: Any, upper_bound: Any, closed: str) -> Self: + def is_between( + self: Self, + lower_bound: Any, + upper_bound: Any, + closed: Literal["left", "right", "none", "both"], + ) -> Self: return reuse_series_implementation( self, "is_between", diff --git a/narwhals/_arrow/series.py b/narwhals/_arrow/series.py index 1e8d09827..193fc25a2 100644 --- a/narwhals/_arrow/series.py +++ b/narwhals/_arrow/series.py @@ -490,7 +490,10 @@ def all(self: Self, *, _return_py_scalar: bool = True) -> bool: ) def is_between( - self, lower_bound: Any, upper_bound: Any, closed: str = "both" + self, + lower_bound: Any, + upper_bound: Any, + closed: Literal["left", "right", "none", "both"], ) -> Self: import pyarrow.compute as pc diff --git a/narwhals/_dask/expr.py b/narwhals/_dask/expr.py index cb20fa616..c9f8c2611 100644 --- a/narwhals/_dask/expr.py +++ b/narwhals/_dask/expr.py @@ -413,10 +413,9 @@ def is_between( self, lower_bound: Self | Any, upper_bound: Self | Any, - closed: str = "both", + closed: Literal["left", "right", "none", "both"] = "both", ) -> Self: - if closed == "none": - closed = "neither" + closed_ = "neither" if closed == "none" else closed return self._from_call( lambda _input, lower_bound, upper_bound, closed: _input.between( lower_bound, upper_bound, closed @@ -424,7 +423,7 @@ def is_between( "is_between", lower_bound=lower_bound, upper_bound=upper_bound, - closed=closed, + closed=closed_, returns_scalar=self._returns_scalar, ) diff --git a/narwhals/_pandas_like/expr.py b/narwhals/_pandas_like/expr.py index 34d05b7eb..c694b3420 100644 --- a/narwhals/_pandas_like/expr.py +++ b/narwhals/_pandas_like/expr.py @@ -262,7 +262,10 @@ def clip(self, lower_bound: Any, upper_bound: Any) -> Self: ) def is_between( - self, lower_bound: Any, upper_bound: Any, closed: str = "both" + self, + lower_bound: Any, + upper_bound: Any, + closed: Literal["left", "right", "none", "both"], ) -> Self: return reuse_series_implementation( self, diff --git a/narwhals/_pandas_like/series.py b/narwhals/_pandas_like/series.py index e5c5e771e..35ec672e4 100644 --- a/narwhals/_pandas_like/series.py +++ b/narwhals/_pandas_like/series.py @@ -263,7 +263,10 @@ def to_list(self) -> Any: return self._native_series.to_list() def is_between( - self, lower_bound: Any, upper_bound: Any, closed: str = "both" + self, + lower_bound: Any, + upper_bound: Any, + closed: Literal["left", "right", "none", "both"], ) -> PandasLikeSeries: ser = self._native_series _, lower_bound = broadcast_align_and_extract_native(self, lower_bound) diff --git a/narwhals/_spark_like/expr.py b/narwhals/_spark_like/expr.py index 66826a6ab..03529ca96 100644 --- a/narwhals/_spark_like/expr.py +++ b/narwhals/_spark_like/expr.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING from typing import Any from typing import Callable +from typing import Literal from typing import Sequence from narwhals._expression_parsing import infer_new_root_output_names @@ -276,7 +277,7 @@ def is_between( self, lower_bound: Any, upper_bound: Any, - closed: str, + closed: Literal["left", "right", "none", "both"], ) -> Self: def _is_between(_input: Column, lower_bound: Any, upper_bound: Any) -> Column: if closed == "both": diff --git a/narwhals/expr.py b/narwhals/expr.py index 653300da8..807a7f04b 100644 --- a/narwhals/expr.py +++ b/narwhals/expr.py @@ -1792,10 +1792,10 @@ def sort(self, *, descending: bool = False, nulls_last: bool = False) -> Self: # --- transform --- def is_between( - self, + self: Self, lower_bound: Any | IntoExpr, upper_bound: Any | IntoExpr, - closed: str = "both", + closed: Literal["left", "right", "none", "both"] = "both", ) -> Self: """Check if this expression is between the given lower and upper bounds. diff --git a/narwhals/series.py b/narwhals/series.py index 7b4cfbf6e..8385b43ad 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -2605,7 +2605,10 @@ def fill_null( ) def is_between( - self, lower_bound: Any | Self, upper_bound: Any | Self, closed: str = "both" + self: Self, + lower_bound: Any | Self, + upper_bound: Any | Self, + closed: Literal["left", "right", "none", "both"] = "both", ) -> Self: """Get a boolean mask of the values that are between the given lower/upper bounds.