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

Skip to content

BUG : deal with empty list passed to boxplot #3571

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
Sep 27, 2014
Merged
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
27 changes: 24 additions & 3 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None):
======== ===================================
label tick label for the boxplot
mean arithemetic mean value
median 50th percentile
med 50th percentile
q1 first quartile (25th percentile)
q3 third quartile (75th percentile)
cilo lower notch around the median
Expand Down Expand Up @@ -1962,13 +1962,34 @@ def _compute_conf_interval(data, med, iqr, bootstrap):

input_whis = whis
for ii, (x, label) in enumerate(zip(X, labels), start=0):

# empty dict
stats = {}
stats['label'] = label

# restore whis to the input values in case it got changed in the loop
whis = input_whis

# note tricksyness, append up here and then mutate below
bxpstats.append(stats)

# if empty, bail
if len(x) == 0:
stats['fliers'] = np.array([])
stats['mean'] = np.nan
stats['med'] = np.nan
stats['q1'] = np.nan
stats['q3'] = np.nan
stats['cilo'] = np.nan
stats['ciho'] = np.nan
stats['whislo'] = np.nan
stats['whishi'] = np.nan
stats['med'] = np.nan
continue

# up-convert to an array, just to be safe
x = np.asarray(x)

# arithmetic mean
stats['mean'] = np.mean(x)

Expand Down Expand Up @@ -2021,9 +2042,9 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
np.compress(x > stats['whishi'], x)
])

# add in teh remaining stats and append to final output
# add in the remaining stats
stats['q1'], stats['med'], stats['q3'] = q1, med, q3
bxpstats.append(stats)


return bxpstats

Expand Down