/
exceptions.py
180 lines (132 loc) · 6.41 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
try:
from polars.polars import (
CategoricalRemappingWarning,
ColumnNotFoundError,
ComputeError,
DuplicateError,
InvalidOperationError,
MapWithoutReturnDtypeWarning,
NoDataError,
OutOfBoundsError,
PolarsError,
PolarsPanicError,
PolarsWarning,
SchemaError,
SchemaFieldNotFoundError,
ShapeError,
StringCacheMismatchError,
StructFieldNotFoundError,
)
except ImportError:
# redefined for documentation purposes when there is no binary
class PolarsError(Exception): # type: ignore[no-redef]
"""Base class for all Polars errors."""
class ColumnNotFoundError(PolarsError): # type: ignore[no-redef, misc]
"""
Exception raised when a specified column is not found.
Example
-------
>>> df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select("b")
polars.exceptions.ColumnNotFoundError: b
"""
class ComputeError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when Polars could not perform an underlying computation."""
class DuplicateError(PolarsError): # type: ignore[no-redef, misc]
"""
Exception raised when a column name is duplicated.
Example
-------
>>> df = pl.DataFrame({"a": [1, 1, 1]})
>>> pl.concat([df, df], how="horizontal")
polars.exceptions.DuplicateError: unable to hstack, column with name "a" already exists
""" # noqa: W505
class InvalidOperationError(PolarsError): # type: ignore[no-redef, misc]
"""
Exception raised when an operation is not allowed (or possible) against a given object or data structure.
Example
-------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.is_in(["x", "y"])
polars.exceptions.InvalidOperationError: `is_in` cannot check for String values in Int64 data
""" # noqa: W505
class NoDataError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when an operation cannot be performed on an empty data structure.""" # noqa: W505
class OutOfBoundsError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when the given index is out of bounds."""
class PolarsPanicError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when an unexpected state causes a panic in the underlying Rust library.""" # noqa: W505
class SchemaError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when an unexpected schema mismatch causes an error."""
class SchemaFieldNotFoundError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when a specified schema field is not found."""
class ShapeError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when trying to perform operations on data structures with incompatible shapes.""" # noqa: W505
class StringCacheMismatchError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when string caches come from different sources."""
class StructFieldNotFoundError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when a specified Struct field is not found."""
class PolarsWarning(Exception): # type: ignore[no-redef]
"""Base class for all Polars warnings."""
class CategoricalRemappingWarning(PolarsWarning): # type: ignore[no-redef, misc]
"""Warning raised when a categorical needs to be remapped to be compatible with another categorical.""" # noqa: W505
class MapWithoutReturnDtypeWarning(PolarsWarning): # type: ignore[no-redef, misc]
"""Warning raised when `map_elements` is performed without specifying the return dtype.""" # noqa: W505
class InvalidAssert(PolarsError): # type: ignore[misc]
"""Exception raised when an unsupported testing assert is made."""
class RowsError(PolarsError): # type: ignore[misc]
"""Exception raised when the number of returned rows does not match expectation."""
class NoRowsReturnedError(RowsError):
"""Exception raised when no rows are returned, but at least one row is expected."""
class TooManyRowsReturnedError(RowsError):
"""Exception raised when more rows than expected are returned."""
class ModuleUpgradeRequired(ModuleNotFoundError):
"""Exception raised when a module is installed but needs to be upgraded."""
class ParameterCollisionError(PolarsError): # type: ignore[misc]
"""Exception raised when the same parameter occurs multiple times."""
class UnsuitableSQLError(PolarsError): # type: ignore[misc]
"""Exception raised when unsuitable SQL is given to a database method."""
class ChronoFormatWarning(PolarsWarning): # type: ignore[misc]
"""
Warning issued when a chrono format string contains dubious patterns.
Polars uses Rust's chrono crate to convert between string data and temporal data.
The patterns used by chrono differ slightly from Python's built-in datetime module.
Refer to the `chrono strftime documentation
<https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_ for the full
specification.
"""
class PolarsInefficientMapWarning(PolarsWarning): # type: ignore[misc]
"""Warning issued when a potentially slow `map_*` operation is performed."""
class TimeZoneAwareConstructorWarning(PolarsWarning): # type: ignore[misc]
"""Warning issued when constructing Series from non-UTC time-zone-aware inputs."""
class UnstableWarning(PolarsWarning): # type: ignore[misc]
"""Warning issued when unstable functionality is used."""
class ArrowError(Exception):
"""Deprecated: will be removed."""
class CustomUFuncWarning(PolarsWarning): # type: ignore[misc]
"""Warning issued when a custom ufunc is handled differently than numpy ufunc would.""" # noqa: W505
__all__ = [
"ArrowError",
"ColumnNotFoundError",
"ComputeError",
"ChronoFormatWarning",
"DuplicateError",
"InvalidOperationError",
"MapWithoutReturnDtypeWarning",
"ModuleUpgradeRequired",
"NoDataError",
"NoRowsReturnedError",
"OutOfBoundsError",
"PolarsInefficientMapWarning",
"CategoricalRemappingWarning",
"PolarsError",
"PolarsPanicError",
"PolarsWarning",
"RowsError",
"SchemaError",
"SchemaFieldNotFoundError",
"ShapeError",
"StringCacheMismatchError",
"StructFieldNotFoundError",
"TooManyRowsReturnedError",
]