Skip to content

Commit

Permalink
inherit all errors from NarwhalsError
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Feb 3, 2025
1 parent e7afaa2 commit c8ced84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 12 additions & 8 deletions narwhals/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from typing_extensions import Self


class NarwhalsError(ValueError):
"""Base class for all Narwhals exceptions."""


class FormattedKeyError(KeyError):
"""KeyError with formatted error message.
Expand All @@ -22,7 +26,7 @@ def __str__(self: Self) -> str:
return self.message


class ColumnNotFoundError(FormattedKeyError):
class ColumnNotFoundError(FormattedKeyError, NarwhalsError):
"""Exception raised when column name isn't present."""

def __init__(self: Self, message: str) -> None:
Expand All @@ -40,15 +44,15 @@ def from_missing_and_available_column_names(
return ColumnNotFoundError(message)


class ShapeError(Exception):
class ShapeError(NarwhalsError):
"""Exception raised when trying to perform operations on data structures with incompatible shapes."""


class InvalidOperationError(Exception):
class InvalidOperationError(NarwhalsError):
"""Exception raised during invalid operations."""


class InvalidIntoExprError(TypeError):
class InvalidIntoExprError(TypeError, NarwhalsError):
"""Exception raised when object can't be converted to expression."""

def __init__(self: Self, message: str) -> None:
Expand All @@ -71,7 +75,7 @@ def from_invalid_type(cls: type, invalid_type: type) -> InvalidIntoExprError:
return InvalidIntoExprError(message)


class AnonymousExprError(ValueError): # pragma: no cover
class AnonymousExprError(NarwhalsError): # pragma: no cover
"""Exception raised when trying to perform operations on anonymous expressions."""

def __init__(self: Self, message: str) -> None:
Expand All @@ -88,23 +92,23 @@ def from_expr_name(cls: type, expr_name: str) -> AnonymousExprError:
return AnonymousExprError(message)


class OrderDependentExprError(ValueError):
class OrderDependentExprError(NarwhalsError):
"""Exception raised when trying to use an order-dependent expressions with LazyFrames."""

def __init__(self: Self, message: str) -> None:
self.message = message
super().__init__(self.message)


class LengthChangingExprError(ValueError):
class LengthChangingExprError(NarwhalsError):
"""Exception raised when trying to use an expression which changes length with LazyFrames."""

def __init__(self: Self, message: str) -> None:
self.message = message
super().__init__(self.message)


class UnsupportedDTypeError(ValueError):
class UnsupportedDTypeError(NarwhalsError):
"""Exception raised when trying to convert to a DType which is not supported by the given backend."""


Expand Down
9 changes: 4 additions & 5 deletions narwhals/stable/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@ def lazy(
the possibility of running entirely lazily.
Arguments:
backend: specifies which lazy backend collect to. This will be the underlying
backend for the resulting Narwhals LazyFrame.
backend: Which lazy backend collect to. This will be the underlying
backend for the resulting Narwhals LazyFrame. If not specified, and the
given library does not support lazy execution, then this will restrict
the API to lazy-only operations.
`backend` can be specified in various ways:
- As `Implementation.<BACKEND>` with `BACKEND` being `DASK`, `DUCKDB`
or `POLARS`.
- As a string: `"dask"`, `"duckdb"` or `"polars"`
- Directly as a module `dask.dataframe`, `duckdb` or `polars`.
backend: The (lazy) implementation to convert to. If not specified, and the
given library does not support lazy execution, then this will restrict
the API to lazy-only operations.
Returns:
A new LazyFrame.
Expand Down

0 comments on commit c8ced84

Please sign in to comment.