10000 BUG: boxplot fails when one column is all NaNs by onesandzeroes · Pull Request #8240 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: boxplot fails when one column is all NaNs
Add test case for empty column

Replace empty arrays with [np.nan]

Add fix to the release notes

Add issue numbers
  • Loading branch information
onesandzeroes committed Sep 11, 2014
commit d645f23afe31d0c225074ab58591c6a78d2be51d
1 change: 1 addition & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (:issue:`8181`).
5 changes: 5 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,11 @@ def _check_ax_limits(col, ax):
self.assertEqual(age_ax._sharey, height_ax)
self.assertIsNone(dummy_ax._sharey)

@slow
def test_boxplot_empty_column(self):
df = DataFrame(np.random.randn(20, 4))
df.loc[:, 0] = np.nan
_check_plot_works(df.boxplot, return_type='axes')

@slow
def test_kde_df(self):
Expand Down
4 changes: 4 additions & 0 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,10 @@ def _get_plot_function(self):
def plotf(ax, y, column_num=None, **kwds):
if y.ndim == 2:
y = [remove_na(v) for v in y]
# Boxplot fails with empty arrays, so need to add a NaN
Copy link
Contributor

Choose a reason for hiding this comment

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

add issue number here too (so in future when someone looks they will have the reference)

# if any cols are empty
# GH 8181
y = [v if v.size > 0 else np.array([np.nan]) for v in y]
else:
y = remove_na(y)
bp = ax.boxplot(y, **kwds)
Expand Down
0