Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: boxplot fails when one column is all NaNs #8240

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 1 commit into from

Conversation

onesandzeroes
Copy link
Contributor

Fixes #8181. Currently the boxplot fails when trying to compute quantiles on an empty array, which numpy can't deal with. Works okay if we use an array with a single np.nan instead, the empty column is just left out of the plot as expected.

I guess that might be a bit of a hack, relying on how numpy deals with a single np.nan in an array versus an empty array? If people think it's too risky to depend on that behaviour I'll try to rethink.

New output:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame(np.random.randn(100, 4))
df.loc[:, 0] = np.nan
df.plot(kind='box')
plt.show()

missing_boxplot

@@ -764,3 +764,4 @@ Bug Fixes
needed interpolating (:issue:`7173`).
- Bug where ``col_space`` was ignored in ``DataFrame.to_string()`` when ``header=False``
(:issue:`8230`).
- Bug where ``Dataframe.boxplot()`` failed when entire column was empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add issue number

@jreback jreback added this to the 0.15.0 milestone Sep 11, 2014
@jreback
Copy link
Contributor

jreback commented Sep 11, 2014

minor comments and squash

@TomAugspurger pass to you, merge at your discretion

Add test case for empty column

Replace empty arrays with [np.nan]

Add fix to the release notes

Add issue numbers
@onesandzeroes
Copy link
Contributor Author

@TomAugspurger this one's had the issue numbers added and then squashed, OK to merge or do I need to come up with a different approach?

@TomAugspurger
Copy link
Contributor

I think this is fine. I'll merge tomorrow when I get connected to wifi again.

@TomAugspurger
Copy link
Contributor

Sorry, I let this get out of date.

Merged via: fb977d7

@tacaswell
Copy link
Contributor

This is more properly addressed by matplotlib/matplotlib#3571

jairideout added a commit to jairideout/scikit-bio that referenced this pull request Oct 6, 2014
Empty distributions are plottable in mpl < 1.4.0. In 1.4.0, a ValueError is raised. This has been fixed in mpl 1.4.0-dev (see matplotlib/matplotlib#3571). In order for skbio.draw.boxplots to support empty distributions across mpl versions, empty distributions are replaced with [np.nan]. See pandas-dev/pandas#8382 and pandas-dev/pandas#8240 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: boxplot fails when one column is all NaNs
4 participants