Skip to content
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

Infer ExtensionDtype based on object #27995

Open
andrewgsavage opened this issue Aug 18, 2019 · 3 comments
Open

Infer ExtensionDtype based on object #27995

andrewgsavage opened this issue Aug 18, 2019 · 3 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement ExtensionArray Extending pandas with custom dtypes or arrays.

Comments

@andrewgsavage
Copy link

Would it be possible to infer ExtensionDtypes based on the objects inside a list/array that are used to construct a series?

Eg with an array of pint's Quantity objects:

>>> array_of_qty
array([<Quantity(67.0, 'meter')>, <Quantity(61.0, 'meter')>,
       <Quantity(30.0, 'meter')>, ..., <Quantity(293.0, 'meter')>,
       <Quantity(886.0, 'meter')>, <Quantity(165.0, 'meter')>],
      dtype=object)

Could pandas infer the dtype as PintType in this command?:

df.elevation = array_of_qty
@jbrockmendel
Copy link
Member

There has been some discussion about this, and so far the consensus is that this would be worthwhile if we can find a performant way to implement it. A PR with a proof of concept might be helpful.

@TomAugspurger
Copy link
Contributor

This probably boils down to

pandas._libs.lib.infer_dtype(...)

being able to return an extension type. Then things should work pretty much everywhere in pandas.

Also, don't do df.elevation = array_of_qty (That should be triggering a warning) 😄

@TomAugspurger TomAugspurger added ExtensionArray Extending pandas with custom dtypes or arrays. Dtype Conversions Unexpected or buggy dtype conversions labels Aug 19, 2019
@andrewgsavage
Copy link
Author

Hmm, that isn't triggering a warning - what are you expecting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Enhancement ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

No branches or pull requests

4 participants