From 2775a7f346c626c34508ee39f001c05266ff96a1 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 25 Sep 2014 08:49:19 -0400 Subject: [PATCH 1/2] BUG : don't assume label in boxpplot_stat If the user does not pass in a label, do not assign one. Fixes #3563 --- lib/matplotlib/cbook.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 4cd1fcca9afe..56d68aa47041 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -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 @@ -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) From 6bcffbe48e1f83f57e499a88f23d9b444e89d5c8 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 26 Sep 2014 22:28:55 -0400 Subject: [PATCH 2/2] TST : modified tests to pass - added check that labels don't get adding by default --- lib/matplotlib/tests/test_cbook.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index d41044c004a4..61d69fd76efd 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -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 = { @@ -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 @@ -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):