Skip to content

Support structural subtyping with ExtensionArray #57634

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

Closed
wants to merge 4 commits into from

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Feb 26, 2024

This is a very naive implementation. Ideally we would move a lot of the extraneous functions / attributes out of the core ExtensionArray class and into a better home

@jbrockmendel
Copy link
Member

move a lot of the extraneous functions / attributes out of the core ExtensionArray class and into a better home

Can you expand on this? Early on when implementing EAs there was an idea that it could be implemented in terms of a small number of primitives (so the EA namespace could stay small) but that idea didn't pan out.

@WillAyd
Copy link
Member Author

WillAyd commented Feb 26, 2024

Yea I am referring to anything that is a method on the ExtensionArray but that is not documented as part of the interface. _values_for_json, _get_repr_footer, etc... work when you use structural typing instead of nominal typing you'd have to re-implement those (see the test case)

@mroeschke mroeschke added the ExtensionArray Extending pandas with custom dtypes or arrays. label Feb 27, 2024
@jbrockmendel
Copy link
Member

So is the suggestion to move those things out of the EA namespace or just to document them as required?

This Protocol approach seems to make it difficult to implement default-but-overridable implementations for things.

@WillAyd
Copy link
Member Author

WillAyd commented Feb 27, 2024

Yea not sure yet how to best move things. Maybe that would require something like ExtensionArrayDefaultOpsMixin?

@jbrockmendel
Copy link
Member

Yea not sure yet how to best move things. Maybe that would require something like ExtensionArrayDefaultOpsMixin?

This seems like a lot of effort to reinvent the idea of a subclass. Is there any evidence that this is a pain point for 3rd parties?

@WillAyd
Copy link
Member Author

WillAyd commented Feb 27, 2024

I am not aware of an existing library asking for this. It would be a new feature for a library that in the future may want to implement a class in an extension without having to interact heavily with the Python runtime

@WillAyd WillAyd marked this pull request as draft February 29, 2024 02:47
@WillAyd
Copy link
Member Author

WillAyd commented Mar 19, 2024

Closing for now - may revisit later

@WillAyd WillAyd closed this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Make ExtensionArray a Protocol
3 participants