diff --git a/narwhals/_polars/series.py b/narwhals/_polars/series.py index 4a931c152..e9ac005d7 100644 --- a/narwhals/_polars/series.py +++ b/narwhals/_polars/series.py @@ -226,17 +226,15 @@ def __invert__(self: Self) -> Self: def is_nan(self: Self) -> Self: native = self._native_series - - if self._backend_version < (1, 18): # pragma: no cover - return self._from_native_series( - pl.select(pl.when(native.is_not_null()).then(native.is_nan()))[ - native.name - ] - ) try: - return self._from_native_series(native.is_nan()) + native_is_nan = native.is_nan() except pl.exceptions.PolarsError as e: raise catch_polars_exception(e) from None + if self._backend_version < (1, 18): # pragma: no cover + return self._from_native_series( + pl.select(pl.when(native.is_not_null()).then(native_is_nan))[native.name] + ) + return self._from_native_series(native_is_nan) def median(self: Self) -> Any: from narwhals.exceptions import InvalidOperationError diff --git a/narwhals/exceptions.py b/narwhals/exceptions.py index 412034c06..011fb9407 100644 --- a/narwhals/exceptions.py +++ b/narwhals/exceptions.py @@ -52,7 +52,7 @@ class InvalidOperationError(NarwhalsError): """Exception raised during invalid operations.""" -class InvalidIntoExprError(NarwhalsError): +class InvalidIntoExprError(TypeError, NarwhalsError): """Exception raised when object can't be converted to expression.""" def __init__(self: Self, message: str) -> None: