Skip to content

Commit 2407734

Browse files
authored
docs: Minor rendering fixups, inherit all exceptions from NarwhalsError (#1919)
1 parent 6df6afe commit 2407734

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

docs/backcompat.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ The following are differences between the main Narwhals namespace and `narwhals.
115115

116116
- Since Narwhals 1.23:
117117

118-
- Passing an `ibis.Table` to `from_native` returns a `LazyFrame`. In
119-
`narwhals.stable.v1`, it returns a `DataFrame` with `level='interchange'`.
120-
- `eager_or_interchange_only` has been removed from `from_native` and `narwhalify`.
121-
- Order-dependent expressions can no longer be used with `narwhals.LazyFrame`.
122-
- The following expressions have been deprecated from the main namespace: `Expr.head`,
123-
`Expr.tail`, `Expr.gather_every`, `Expr.sample`, `Expr.arg_true`, `Expr.sort`.
118+
- Passing an `ibis.Table` to `from_native` returns a `LazyFrame`. In
119+
`narwhals.stable.v1`, it returns a `DataFrame` with `level='interchange'`.
120+
- `eager_or_interchange_only` has been removed from `from_native` and `narwhalify`.
121+
- Order-dependent expressions can no longer be used with `narwhals.LazyFrame`.
122+
- The following expressions have been deprecated from the main namespace: `Expr.head`,
123+
`Expr.tail`, `Expr.gather_every`, `Expr.sample`, `Expr.arg_true`, `Expr.sort`.
124124

125125
- Since Narwhals 1.21, passing a `DuckDBPyRelation` to `from_native` returns a `LazyFrame`. In
126126
`narwhals.stable.v1`, it returns a `DataFrame` with `level='interchange'`.

narwhals/dataframe.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -520,18 +520,17 @@ def lazy(
520520
the possibility of running entirely lazily.
521521
522522
Arguments:
523-
backend: specifies which lazy backend collect to. This will be the underlying
524-
backend for the resulting Narwhals LazyFrame.
523+
backend: Which lazy backend collect to. This will be the underlying
524+
backend for the resulting Narwhals LazyFrame. If not specified, and the
525+
given library does not support lazy execution, then this will restrict
526+
the API to lazy-only operations.
525527
526528
`backend` can be specified in various ways:
527529
528530
- As `Implementation.<BACKEND>` with `BACKEND` being `DASK`, `DUCKDB`
529531
or `POLARS`.
530532
- As a string: `"dask"`, `"duckdb"` or `"polars"`
531533
- Directly as a module `dask.dataframe`, `duckdb` or `polars`.
532-
backend: The (lazy) implementation to convert to. If not specified, and the
533-
given library does not support lazy execution, then this will restrict
534-
the API to lazy-only operations.
535534
536535
Returns:
537536
A new LazyFrame.

narwhals/exceptions.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from typing_extensions import Self
77

88

9+
class NarwhalsError(ValueError):
10+
"""Base class for all Narwhals exceptions."""
11+
12+
913
class FormattedKeyError(KeyError):
1014
"""KeyError with formatted error message.
1115
@@ -22,7 +26,7 @@ def __str__(self: Self) -> str:
2226
return self.message
2327

2428

25-
class ColumnNotFoundError(FormattedKeyError):
29+
class ColumnNotFoundError(FormattedKeyError, NarwhalsError):
2630
"""Exception raised when column name isn't present."""
2731

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

4246

43-
class ShapeError(Exception):
47+
class ShapeError(NarwhalsError):
4448
"""Exception raised when trying to perform operations on data structures with incompatible shapes."""
4549

4650

47-
class InvalidOperationError(Exception):
51+
class InvalidOperationError(NarwhalsError):
4852
"""Exception raised during invalid operations."""
4953

5054

51-
class InvalidIntoExprError(TypeError):
55+
class InvalidIntoExprError(TypeError, NarwhalsError):
5256
"""Exception raised when object can't be converted to expression."""
5357

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

7377

74-
class AnonymousExprError(ValueError): # pragma: no cover
78+
class AnonymousExprError(NarwhalsError): # pragma: no cover
7579
"""Exception raised when trying to perform operations on anonymous expressions."""
7680

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

9094

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

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

98102

99-
class LengthChangingExprError(ValueError):
103+
class LengthChangingExprError(NarwhalsError):
100104
"""Exception raised when trying to use an expression which changes length with LazyFrames."""
101105

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

106110

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

110114

narwhals/stable/v1/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,17 @@ def lazy(
183183
the possibility of running entirely lazily.
184184
185185
Arguments:
186-
backend: specifies which lazy backend collect to. This will be the underlying
187-
backend for the resulting Narwhals LazyFrame.
186+
backend: Which lazy backend collect to. This will be the underlying
187+
backend for the resulting Narwhals LazyFrame. If not specified, and the
188+
given library does not support lazy execution, then this will restrict
189+
the API to lazy-only operations.
188190
189191
`backend` can be specified in various ways:
190192
191193
- As `Implementation.<BACKEND>` with `BACKEND` being `DASK`, `DUCKDB`
192194
or `POLARS`.
193195
- As a string: `"dask"`, `"duckdb"` or `"polars"`
194196
- Directly as a module `dask.dataframe`, `duckdb` or `polars`.
195-
backend: The (lazy) implementation to convert to. If not specified, and the
196-
given library does not support lazy execution, then this will restrict
197-
the API to lazy-only operations.
198197
199198
Returns:
200199
A new LazyFrame.

0 commit comments

Comments
 (0)