pola-rs/polars · error · AttributeRemovedError

accessing ` ` from the top-level `polars` module was…

Error message

accessing `{name}` from the top-level `polars` module was deprecated in version 1.0.0. Import it directly from the `polars.exceptions` module instead, e.g.: `from polars.exceptions import {name}`

What it means

Accessing an exception class (e.g. `polars.ComputeError`) from the top-level `polars` module triggers `__getattr__`, which raises `AttributeRemovedError` because exception classes were moved to `polars.exceptions` in version 1.0.0. The library no longer re-exports exceptions at top level and directs you to import them from their new home. This is a hard deprecation removal, not a soft warning.

Solutions

  1. Replace `polars.<Name>` with `polars.exceptions.<Name>` in the expression that raised.
  2. Change the import at the top of the file: `from polars.exceptions import <Name>` and reference the bare name.
  3. Run a project-wide search for `polars\.[A-Z]` and fix all exception-class references at once.

Example fix

// before
except polars.ComputeError as e:
    ...

// after
from polars.exceptions import ComputeError
except ComputeError as e:
    ...
Defensive patterns

Strategy: type-guard

Validate before calling

import polars.exceptions as plex
assert hasattr(plex, 'ComputeError')

Type guard

def is_polars_exception(name: str) -> bool:
    import polars.exceptions as plex
    return hasattr(plex, name)

Try / catch

try:
    err_cls = getattr(polars, 'ComputeError')
except AttributeError:
    from polars.exceptions import ComputeError as err_cls

Prevention

When it happens

Trigger: Any `polars.<ExceptionName>` attribute access where the name exists in `polars.exceptions`, e.g. `except polars.ShapeError:` or `polars.NoDataError`, after upgrading to polars >= 1.0.0.

Common situations: Upgrading from polars <1.0 to >=1.0 with old exception-handling code; copying older tutorials or StackOverflow snippets that catch `polars.ComputeError`; IDE auto-imports inserting `polars.SomeError` references.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/00949e2da40f89e4. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/__init__.py:533

    # This causes typechecking to resolve any Polars module attribute
    # as Any regardless of existence so we check for TYPE_CHECKING, see #24334.
    def __getattr__(name: str) -> Any:
        # Backwards compatibility for plugins. This used to be called `polars.polars`,
        # but is now `polars._plr`.
        if name == "polars":
            return plr
        elif name == "_allocator":
            return plr._allocator

        # Deprecate re-export of exceptions at top-level
        if name in dir(exceptions):
            msg = (
                f"accessing `{name}` from the top-level `polars` module was deprecated "
                "in version 1.0.0. Import it directly from the `polars.exceptions` module "
                f"instead, e.g.: `from polars.exceptions import {name}`"
            )
            raise exceptions.AttributeRemovedError(msg)

        # Deprecate data type groups at top-level
        import polars.datatypes.group as dtgroup

        if name in dir(dtgroup):
            msg = (
                f"`{name}` was deprecated in version 1.0.0. Define your own data type groups or "
                "use the `polars.selectors` module for selecting columns of a certain data type."
            )
            raise exceptions.AttributeRemovedError(msg)

        # Functions removed in 2.0
        removed = {
            "arctan2d": "use `arctan2` followed by `.degrees()` instead.",
            "groups": "use `df.with_row_index().group_by(...).agg(pl.col('index'))` instead.",
            "read_csv_batched": "use `scan_csv` instead, in conjunction with `LazyFrame.collect(engine='streaming')`.",
            "threadpool_size": "it was renamed; use `thread_pool_size` instead.",
        }

View on GitHub (pinned to fe841f959e)