Skip to content

ENH: Make ExtensionArray a Protocol #57633

Open
@WillAyd

Description

@WillAyd

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

The current pandas ExtensionArray is a standard Python class, and throughout our code base we do things like isinstance(obj, ExtensionArray) to determine at runtime if an object is an instance of the ExtensionArray.

While this works for classes implemented purely in Python that may inherit from a Python class, it does not work with extension classes that are implemented in either Cython, pybind11, nanobind, etc... See https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#subclassing for documentation of this limitation in Cython

As such, unless you implement your extension purely in Python it will not work correctly as an ExtensionArray

Feature Description

PEP 544 describes the runtime_checkable decorator that in theory can solve this issue without any major changes to our code base (ignoring any performance implications for now)

Alternative Solutions

Not sure there are any - I may be wrong but I do not think extension types in Python can inherit from Python types

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions