pola-rs/polars · error · AttributeRemovedError

`{name}` was removed in version {version}

Error message

`{name}` was removed in version {version}

What it means

Raised by polars' expired-API machinery when code accesses an attribute (or dunder parameter) that was fully removed in a given polars version. The message includes the attribute name, removal version, and an optional migration hint. It exists to give a hard, informative failure instead of a bare AttributeError after the deprecation window closed.

Source

Thrown at py-polars/src/polars/_utils/expired.py:62

    """
    Raise an `AttributeError` for a removed attribute.

    Parameters
    ----------
    obj
        The object from which the attribute was removed.
    name
        The name of the removed attribute.
    attributes
        A dictionary mapping removed attribute names to hints for replacement.
    version
        The version in which the attribute was removed.
    """
    if name in attributes:
        hint = attributes[name]
        msg = f"`{name}` was removed in version {version}"
        msg = f"{msg}." if hint is None else f"{msg}; {hint}"
        raise AttributeRemovedError(msg, name=name, obj=obj)


def getattr_fallback(
    obj: object, superclass: object, name: str, *, meta: bool = False
) -> Any:
    """
    Raise an `AttributeError` for a non-existent attribute.

    Parameters
    ----------
    obj
        The object on which the attribute was accessed.
    superclass
        The superclass of the object used to attempt to access the attribute.
    name
        The name of the non-existent attribute.
    meta
        Whether the object is a metaclass (default: False).

View on GitHub (pinned to 5d8ebabf11)

Solutions

  1. Follow the hint in the error message (it names the replacement API)
  2. Search the polars changelog / migration guide for the attribute name and version
  3. Update the third-party library pinning the removed attribute
  4. Pin polars to the older version only as a temporary stopgap while migrating

Example fix

# before
df._rows
# after
df.rows()
Defensive patterns

Strategy: validation

Validate before calling

removed = {'_rows': 'rows()', 'spearman_corr': 'corr'}
if hasattr(obj, name := 'old_attr') and name in removed:
    raise RuntimeError(f'use {removed[name]} instead')

Type guard

def uses_removed_attr(obj: object, name: str) -> bool:
    try:
        obj.__getattr__  # noqa
        return name in getattr(type(obj), '_removed_attributes', {})
    except AttributeError:
        return False

Try / catch

try:
    getattr(obj, name)
except (AttributeError, Exception) as e:
    if 'was removed in version' in str(e):
        # parse hint and migrate
        raise

Prevention

When it happens

Trigger: Calling raise_for_removed_attributes (usually wired via __getattr__ on classes like old DataFrame/Expr methods) after upgrading polars past the version listed in the message; e.g. df._rows, Expr.spearman_corr, or other attributes registered in the removal table.

Common situations: Upgrading py-polars across a major/minor release while user code or a third-party library still touches removed private/public attributes; stale notebooks or generated code referencing old APIs.

Related errors


AI-assisted analysis of pola-rs/polars@5d8ebabf11 (2026-08-28). Data as JSON: /api/errors/f74636f7e3f32f3d. Report an issue: GitHub.