diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 0fb1acecb..b055fed12 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -16,6 +16,7 @@ from narwhals.dependencies import get_polars from narwhals.dependencies import is_numpy_array +from narwhals.exceptions import OrderDependentExprError from narwhals.schema import Schema from narwhals.translate import to_native from narwhals.utils import find_stacklevel @@ -3646,7 +3647,7 @@ def _extract_compliant(self, arg: Any) -> Any: " In a future version of Narwhals, a `order_by` argument will be added and \n" " they will be supported." ) - raise TypeError(msg) + raise OrderDependentExprError(msg) return arg._to_compliant_expr(self.__narwhals_namespace__()) if get_polars() is not None and "polars" in str(type(arg)): # pragma: no cover msg = ( diff --git a/narwhals/exceptions.py b/narwhals/exceptions.py index 61447e54f..9b05e3ba8 100644 --- a/narwhals/exceptions.py +++ b/narwhals/exceptions.py @@ -83,6 +83,14 @@ def from_expr_name(cls, expr_name: str) -> AnonymousExprError: return AnonymousExprError(message) +class OrderDependentExprError(ValueError): + """Exception raised when trying to use an order-dependent expressions with LazyFrames.""" + + def __init__(self, message: str) -> None: + self.message = message + super().__init__(self.message) + + class UnsupportedDTypeError(ValueError): """Exception raised when trying to convert to a DType which is not supported by the given backend."""