Skip to content

Commit

Permalink
docs(python): Examples for errors (#13724)
Browse files Browse the repository at this point in the history
  • Loading branch information
NedJWestern authored Apr 13, 2024
1 parent 33c04d5 commit 920f96f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions py-polars/polars/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,40 @@ 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."""
"""
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."""
"""
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.""" # noqa: W505
"""
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
Expand Down

0 comments on commit 920f96f

Please sign in to comment.