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

Skip to content

Commit 40720ef

Browse files
committed
Merge pull request #3566 from tacaswell/fix_bxp_label
BUG : don't assume label in boxpplot_stat
2 parents ccc7afb + 6bcffbe commit 40720ef

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/matplotlib/cbook.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
unicode_literals)
1111

1212
import six
13-
from six.moves import xrange
13+
from six.moves import xrange, zip
14+
from itertools import repeat
1415

1516
import datetime
1617
import errno
@@ -1956,7 +1957,7 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
19561957

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

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

19661967
# empty dict
19671968
stats = {}
1968-
stats['label'] = label
1969+
if label is not None:
1970+
stats['label'] = label
19691971

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

lib/matplotlib/tests/test_cbook.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def setup(self):
121121
'q1': 1.3597529879465153,
122122
'q3': 14.85246294739361,
123123
'whishi': 27.899688243699629,
124-
'whislo': 0.042143774965502923,
125-
'label': 1
124+
'whislo': 0.042143774965502923
126125
}
127126

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

139-
self.known_res_with_labels = {
140-
'label': 'Test1'
141-
}
142-
143138
self.known_res_percentiles = {
144139
'whislo': 0.1933685896907924,
145140
'whishi': 42.232049135969874
@@ -229,11 +224,15 @@ def test_results_whiskers_percentiles(self):
229224
)
230225

231226
def test_results_withlabels(self):
232-
labels = ['Test1', 2, 3, 4]
227+
labels = ['Test1', 2, 'ardvark', 4]
233228
results = cbook.boxplot_stats(self.data, labels=labels)
234229
res = results[0]
235-
for key in list(self.known_res_with_labels.keys()):
236-
assert_equal(res[key], self.known_res_with_labels[key])
230+
for lab, res in zip(labels, results):
231+
assert_equal(res['label'], lab)
232+
233+
results = cbook.boxplot_stats(self.data)
234+
for res in results:
235+
assert('label' not in res)
237236

238237
@raises(ValueError)
239238
def test_label_error(self):

0 commit comments

Comments
 (0)