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): Add docstring examples for Exceptions #15800

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
39 changes: 35 additions & 4 deletions py-polars/polars/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,47 @@ class InvalidOperationError(PolarsError): # type: ignore[no-redef, misc]
""" # 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
"""
Exception raised when an operation cannot be performed on an empty data structure.

Example
-------
>>> pl.from_dicts({})
polars.exceptions.NoDataError: no data, cannot infer schema
""" # noqa: W505

class OutOfBoundsError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when the given index is out of bounds."""
"""
Exception raised when the given index is out of bounds.

Example
-------
>>> s = pl.Series("a", [1, 2, 3])
>>> s.gather(3)
polars.exceptions.OutOfBoundsError: gather indices are 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
"""
Exception raised when an unexpected state causes a panic in the underlying Rust library.

Example
-------
>>> a = pl.Series("a", [1, 2, 3])
>>> b = pl.Series("a", [4, 5])
>>> a * b
pyo3_runtime.PanicException: Cannot apply operation on arrays of different lengths
""" # noqa: W505

class SchemaError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when an unexpected schema mismatch causes an error."""
"""
Exception raised when an unexpected schema mismatch causes an error.

Example
-------
>>> pl.Series([0, 1, 0]).any()
polars.exceptions.SchemaError: invalid series dtype: expected `Boolean`, got `i64`
""" # noqa: W505

class SchemaFieldNotFoundError(PolarsError): # type: ignore[no-redef, misc]
"""Exception raised when a specified schema field is not found."""
Expand Down
Loading