Skip to content

Plotting ExtensionArrays #26173

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
andrewgsavage opened this issue Apr 21, 2019 · 6 comments
Closed

Plotting ExtensionArrays #26173

andrewgsavage opened this issue Apr 21, 2019 · 6 comments
Labels
Enhancement ExtensionArray Extending pandas with custom dtypes or arrays. Visualization plotting

Comments

@andrewgsavage
Copy link

I'd like to plot data from an ExtensionArray. This currently results in an error TypeError: Empty 'DataFrame': no numeric data to plot

This is because the EA data is filtered out. Adding the ExtensionDtype to the filter criteria makes the plot work.
https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/_core.py#L367

numeric_data = data.select_dtypes(include=[np.number,
                                               "datetime",
                                               "datetimetz",
                                               "timedelta", 
                                               pint.PintType])

Could we get a property of the ExtensionDtype that flags the dtype as holding plotable numeric data?

@andrewgsavage
Copy link
Author

related issue hgrecco/pint-pandas#9

@TomAugspurger
Copy link
Contributor

What version of pandas?

#25590 coerces EAs to ndarray before plotting. If np.asarray(your_array) returns a numeric type then it should be passed through to matplotlib, though it'll be a regular NumPy dtype, not your extension dtype. Does that suffice?

@andrewgsavage
Copy link
Author

andrewgsavage commented Apr 22, 2019

'0.25.0.dev0+430.gc79b7bb' - from a few days ago with that merge included.

np.asarray(your_array) return an object dtype, so is filtered out by select_dtypes, eg:
np.array(df.length)
array([<Quantity(1, 'meter')>, <Quantity(2, 'meter')>], dtype=object)

so no it doesn't suffice.

Passing quantity objects as opposed to floats to matploblib will allow the units converting part of matplotlib to work.*

*with some changes to pint. Alternatively the ExtensionArray could provide a function to return something plotable, so we can provide <Quantity(array([0, 1]), 'meter')> to matplotlib

@gfyoung gfyoung added the Visualization plotting label Apr 23, 2019
@jorisvandenbossche jorisvandenbossche added the ExtensionArray Extending pandas with custom dtypes or arrays. label Apr 23, 2019
@andrewgsavage
Copy link
Author

@TomAugspurger have you had a chance to look at this?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 19, 2019 via email

@andrewgsavage
Copy link
Author

fixed by #38246

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. Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants