6
6
from typing_extensions import Self
7
7
8
8
9
+ class NarwhalsError (ValueError ):
10
+ """Base class for all Narwhals exceptions."""
11
+
12
+
9
13
class FormattedKeyError (KeyError ):
10
14
"""KeyError with formatted error message.
11
15
@@ -22,7 +26,7 @@ def __str__(self: Self) -> str:
22
26
return self .message
23
27
24
28
25
- class ColumnNotFoundError (FormattedKeyError ):
29
+ class ColumnNotFoundError (FormattedKeyError , NarwhalsError ):
26
30
"""Exception raised when column name isn't present."""
27
31
28
32
def __init__ (self : Self , message : str ) -> None :
@@ -40,15 +44,15 @@ def from_missing_and_available_column_names(
40
44
return ColumnNotFoundError (message )
41
45
42
46
43
- class ShapeError (Exception ):
47
+ class ShapeError (NarwhalsError ):
44
48
"""Exception raised when trying to perform operations on data structures with incompatible shapes."""
45
49
46
50
47
- class InvalidOperationError (Exception ):
51
+ class InvalidOperationError (NarwhalsError ):
48
52
"""Exception raised during invalid operations."""
49
53
50
54
51
- class InvalidIntoExprError (TypeError ):
55
+ class InvalidIntoExprError (TypeError , NarwhalsError ):
52
56
"""Exception raised when object can't be converted to expression."""
53
57
54
58
def __init__ (self : Self , message : str ) -> None :
@@ -71,7 +75,7 @@ def from_invalid_type(cls: type, invalid_type: type) -> InvalidIntoExprError:
71
75
return InvalidIntoExprError (message )
72
76
73
77
74
- class AnonymousExprError (ValueError ): # pragma: no cover
78
+ class AnonymousExprError (NarwhalsError ): # pragma: no cover
75
79
"""Exception raised when trying to perform operations on anonymous expressions."""
76
80
77
81
def __init__ (self : Self , message : str ) -> None :
@@ -88,23 +92,23 @@ def from_expr_name(cls: type, expr_name: str) -> AnonymousExprError:
88
92
return AnonymousExprError (message )
89
93
90
94
91
- class OrderDependentExprError (ValueError ):
95
+ class OrderDependentExprError (NarwhalsError ):
92
96
"""Exception raised when trying to use an order-dependent expressions with LazyFrames."""
93
97
94
98
def __init__ (self : Self , message : str ) -> None :
95
99
self .message = message
96
100
super ().__init__ (self .message )
97
101
98
102
99
- class LengthChangingExprError (ValueError ):
103
+ class LengthChangingExprError (NarwhalsError ):
100
104
"""Exception raised when trying to use an expression which changes length with LazyFrames."""
101
105
102
106
def __init__ (self : Self , message : str ) -> None :
103
107
self .message = message
104
108
super ().__init__ (self .message )
105
109
106
110
107
- class UnsupportedDTypeError (ValueError ):
111
+ class UnsupportedDTypeError (NarwhalsError ):
108
112
"""Exception raised when trying to convert to a DType which is not supported by the given backend."""
109
113
110
114
0 commit comments