Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(python): Examples for errors #13724

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions py-polars/polars/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,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