pola-rs/polars · error · ValueError

extension type ' ' is already registered

Error message

extension type '{ext_name}' is already registered

What it means

register_extension_type maintains a global _REGISTRY keyed by the extension name; registering the same extension type name twice raises ValueError. The registry can only hold one implementation per Arrow extension name, so duplicate registration is treated as a programming error.

Solutions

  1. Guard registration: only call if not already registered (use unregister_extension_type or check first).
  2. Call unregister_extension_type(ext_name) before re-registering.
  3. Move registration into an idempotent init function (module-level singleton / functools.cache).

Example fix

// before
register_extension_type(MyType)
# ... cell re-run ...
register_extension_type(MyType)  # ValueError
// after
if MyType.__arrow_ext__name not registered:
    register_extension_type(MyType)
# or
unregister_extension_type(MyType)
register_extension_type(MyType)
Defensive patterns

Strategy: try-catch

Validate before calling

from polars.datatypes.extension import register_extension_type, unregister_extension_type
import contextlib
with contextlib.suppress(ValueError):
    register_extension_type(MyType)  # idempotent registration

Try / catch

try:
    register_extension_type(MyType)
except ValueError as e:
    if "already registered" in str(e):
        pass  # idempotent: already registered
    else:
        raise

Prevention

When it happens

Trigger: Calling polars.datatypes.extension.register_extension_type(MyType) twice (e.g. module-level registration executed again on re-import/reload, notebook cell re-run, or plugin imported under two paths); registering a name that ships registered in polars.

Common situations: Notebook re-execution of a registration cell; importlib.reload of a module containing top-level register_extension_type calls; duplicate plugin installs under different module names.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/datatypes/extension.py:30


@unstable()
def register_extension_type(
    ext_name: str,
    ext_class: type[dt.BaseExtension] | None = None,
    *,
    as_storage: bool = False,
) -> None:
    """
    Register the extension type for the given extension name.

    .. warning::
        This functionality is currently considered **unstable**. It may be
        changed at any point without it being considered a breaking change.
    """
    if "ext_name" in _REGISTRY:
        msg = f"extension type '{ext_name}' is already registered"
        raise ValueError(msg)

    if as_storage:
        assert ext_class is None, "cannot specify ext_class when as_storage is True"
        _REGISTRY[ext_name] = "storage"
        with contextlib.suppress(NameError):  # _plr module may be unavailable
            _register_extension_type(ext_name, None)
    else:
        assert not as_storage, "as_storage must be False when ext_class is provided"
        assert isinstance(ext_class, type)
        assert issubclass(ext_class, dt.BaseExtension)
        _REGISTRY[ext_name] = ext_class
        with contextlib.suppress(NameError):  # _plr module may be unavailable
            _register_extension_type(ext_name, ext_class)


@unstable()
def unregister_extension_type(ext_name: str) -> None:
    """

View on GitHub (pinned to fe841f959e)