Skip to content
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

BUG : don't assume label in boxpplot_stat #3566

Merged
merged 2 commits into from Sep 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/matplotlib/cbook.py
Expand Up @@ -10,7 +10,8 @@
unicode_literals)

import six
from six.moves import xrange
from six.moves import xrange, zip
from itertools import repeat

import datetime
import errno
Expand Down Expand Up @@ -1948,14 +1949,15 @@ def _compute_conf_interval(data, med, iqr, bootstrap):

ncols = len(X)
if labels is None:
labels = [str(i) for i in range(1, ncols+1)]
labels = repeat(None)
elif len(labels) != ncols:
raise ValueError("Dimensions of labels and X must be compatible")

for ii, (x, label) in enumerate(zip(X, labels), start=0):
# empty dict
stats = {}
stats['label'] = label
if label is not None:
stats['label'] = label

# arithmetic mean
stats['mean'] = np.mean(x)
Expand Down
17 changes: 8 additions & 9 deletions lib/matplotlib/tests/test_cbook.py
Expand Up @@ -121,8 +121,7 @@ def setup(self):
'q1': 1.3597529879465153,
'q3': 14.85246294739361,
'whishi': 27.899688243699629,
'whislo': 0.042143774965502923,
'label': 1
'whislo': 0.042143774965502923
}

self.known_bootstrapped_ci = {
Expand All @@ -136,10 +135,6 @@ def setup(self):
'fliers': np.array([92.55467075, 87.03819018]),
}

self.known_res_with_labels = {
'label': 'Test1'
}

self.known_res_percentiles = {
'whislo': 0.1933685896907924,
'whishi': 42.232049135969874
Expand Down Expand Up @@ -229,11 +224,15 @@ def test_results_whiskers_percentiles(self):
)

def test_results_withlabels(self):
labels = ['Test1', 2, 3, 4]
labels = ['Test1', 2, 'ardvark', 4]
results = cbook.boxplot_stats(self.data, labels=labels)
res = results[0]
for key in list(self.known_res_with_labels.keys()):
assert_equal(res[key], self.known_res_with_labels[key])
for lab, res in zip(labels, results):
assert_equal(res['label'], lab)

results = cbook.boxplot_stats(self.data)
for res in results:
assert('label' not in res)

@raises(ValueError)
def test_label_error(self):
Expand Down