Skip to content

Commit

Permalink
Merge pull request #3566 from tacaswell/fix_bxp_label
Browse files Browse the repository at this point in the history
BUG : don't assume label in boxpplot_stat
  • Loading branch information
mdboom committed Sep 27, 2014
2 parents ccc7afb + 6bcffbe commit 40720ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
8 changes: 5 additions & 3 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
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 @@ -1956,7 +1957,7 @@ 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")

Expand All @@ -1965,7 +1966,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap):

# empty dict
stats = {}
stats['label'] = label
if label is not None:
stats['label'] = label

# restore whis to the input values in case it got changed in the loop
whis = input_whis
Expand Down
17 changes: 8 additions & 9 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
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

0 comments on commit 40720ef

Please sign in to comment.