Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix violinplot support list of pandas.Series #16530

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

Merged
merged 1 commit into from
Mar 30, 2020

Conversation

timhoffm
Copy link
Member

PR Summary

Fixes #15272.

Reason was that _kde_method tried to get the first element using X[0], however for pandas objects, that looks up 0 in the index, which may not be present.

@timhoffm timhoffm added this to the v3.3.0 milestone Feb 16, 2020
@dstansby
Copy link
Member

Worth adding a test?

@tacaswell
Copy link
Member

The other option is we have a safe_first_element function in cbook, not sure which is better here though.

@timhoffm timhoffm force-pushed the fix-violinplot-pd-series branch from b8a618e to 4a80e64 Compare March 4, 2020 15:33
@timhoffm
Copy link
Member Author

timhoffm commented Mar 4, 2020

@dstansby Test added.

@tacaswell I think it's safer to convert to ndarray instead of safe_first_element() because the passed object X needs to provide more array-like functionality than just indexing the first element:

if np.all(X[0] == X):
    return (X[0] == coords).astype(float)
kde = mlab.GaussianKDE(X, bw_method)

While I think, the first two lines would work for pandas.Series when using safe_first_element(), I'm not sure about GaussianKDE, at least its docstring claims to need a ndarray.

@anntzer anntzer merged commit 0e4685b into matplotlib:master Mar 30, 2020
@timhoffm timhoffm deleted the fix-violinplot-pd-series branch March 30, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Axes.violinplot has small issue in using pandas.DataFrame without index 0.
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.