Skip to content

Add ExtesnsionDtype.empty classmethod #19600

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
TomAugspurger opened this issue Feb 8, 2018 · 5 comments · Fixed by #45024
Closed

Add ExtesnsionDtype.empty classmethod #19600

TomAugspurger opened this issue Feb 8, 2018 · 5 comments · Fixed by #45024
Labels
Enhancement ExtensionArray Extending pandas with custom dtypes or arrays. Internals Related to non-user accessible pandas implementation
Milestone

Comments

@TomAugspurger
Copy link
Contributor

This would let us provide a default construct_from_string method.

It seems we could have a default implementation for ExtensionDtype.construct_from_string ? (I now just copy pasted from the decimal example, and I think json example also has the same basic one)

The default would have to rely on ExtensionDtype() being constructable with no arguments, or an ExtensionDtype.empty method. For many that'll be

@classmethod
def empty(cls):
    return cls()

which is easier than implementing construct_from_string. Maybe call it from_empty.

@TomAugspurger TomAugspurger added API Design Internals Related to non-user accessible pandas implementation Difficulty Intermediate labels Feb 8, 2018
@TomAugspurger TomAugspurger added this to the Next Major Release milestone Feb 8, 2018
@jorisvandenbossche
Copy link
Member

The default would have to rely on ExtensionDtype() being constructable with no arguments

Why not just rely on that assumption directly for a default implementation of construct_from_string ?
The we don't need a new method?

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Feb 9, 2018

So if a class doesn't support ExtensionDtype() called with no arguments, we'll get an exception either way. My hope was that implementing .empty / .from_empty is easier than implementing .construct_from_string.

@jreback
Copy link
Contributor

jreback commented Feb 9, 2018

EA should have this method
maybe make dtype required?

@jorisvandenbossche
Copy link
Member

What has this to do with ExtensionArray itself ?

@jreback
Copy link
Contributor

jreback commented Feb 9, 2018

sorry thought the top was on empty on EA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ExtensionArray Extending pandas with custom dtypes or arrays. Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants