Skip to content

Commit ec331f0

Browse files
author
Tom Augspurger
committed
Merge pull request #8393 from TomAugspurger/pie-nan-fu
TST: Fix failing pie plot tests
2 parents 1f504fe + 1ab045d commit ec331f0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pandas/tests/test_graphics.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def test_pie_series(self):
635635
series = Series([1, 2, np.nan, 4],
636636
index=['a', 'b', 'c', 'd'], name='YLABEL')
637637
ax = _check_plot_works(series.plot, kind='pie')
638-
self._check_text_labels(ax.texts, series.index)
638+
self._check_text_labels(ax.texts, ['a', 'b', '', 'd'])
639639

640640
def test_pie_nan(self):
641641
s = Series([1, np.nan, 1, 1])
@@ -2798,13 +2798,17 @@ def test_pie_df_nan(self):
27982798

27992799
base_expected = ['0', '1', '2', '3']
28002800
for i, ax in enumerate(axes):
2801-
expected = list(base_expected) # copy
2801+
expected = list(base_expected) # force copy
28022802
expected[i] = ''
28032803
result = [x.get_text() for x in ax.texts]
28042804
self.assertEqual(result, expected)
28052805
# legend labels
2806-
self.assertEqual([x.get_text() for x in ax.get_legend().get_texts()],
2807-
base_expected)
2806+
# NaN's not included in legend with subplots
2807+
# see https://github.com/pydata/pandas/issues/8390
2808+
self.assertEqual([x.get_text() for x in
2809+
ax.get_legend().get_texts()],
2810+
base_expected[:i] + base_expected[i+1:])
2811+
28082812
def test_errorbar_plot(self):
28092813
d = {'x': np.arange(12), 'y': np.arange(12, 0, -1)}
28102814
df = DataFrame(d)

pandas/tools/plotting.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,11 @@ def blank_labeler(label, value):
20582058
# labels is used for each wedge's labels
20592059
# Blank out labels for values of 0 so they don't overlap
20602060
# with nonzero wedges
2061-
blabels = [blank_labeler(label, value) for
2062-
label, value in zip(labels, y)]
2061+
if labels is not None:
2062+
blabels = [blank_labeler(label, value) for
2063+
label, value in zip(labels, y)]
2064+
else:
2065+
blabels = None
20632066
results = ax.pie(y, labels=blabels, **kwds)
20642067

20652068
if kwds.get('autopct', None) is not None:

0 commit comments

Comments
 (0)