diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 7e9b562ba0014..fac6a4d83e13b 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -635,7 +635,7 @@ def test_pie_series(self): series = Series([1, 2, np.nan, 4], index=['a', 'b', 'c', 'd'], name='YLABEL') ax = _check_plot_works(series.plot, kind='pie') - self._check_text_labels(ax.texts, series.index) + self._check_text_labels(ax.texts, ['a', 'b', '', 'd']) def test_pie_nan(self): s = Series([1, np.nan, 1, 1]) @@ -2798,13 +2798,17 @@ def test_pie_df_nan(self): base_expected = ['0', '1', '2', '3'] for i, ax in enumerate(axes): - expected = list(base_expected) # copy + expected = list(base_expected) # force copy expected[i] = '' result = [x.get_text() for x in ax.texts] self.assertEqual(result, expected) # legend labels - self.assertEqual([x.get_text() for x in ax.get_legend().get_texts()], - base_expected) + # NaN's not included in legend with subplots + # see https://github.com/pydata/pandas/issues/8390 + self.assertEqual([x.get_text() for x in + ax.get_legend().get_texts()], + base_expected[:i] + base_expected[i+1:]) + def test_errorbar_plot(self): d = {'x': np.arange(12), 'y': np.arange(12, 0, -1)} df = DataFrame(d) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 7b295d9dd8fb8..0b1a0ceb8da60 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -2058,8 +2058,11 @@ def blank_labeler(label, value): # labels is used for each wedge's labels # Blank out labels for values of 0 so they don't overlap # with nonzero wedges - blabels = [blank_labeler(label, value) for - label, value in zip(labels, y)] + if labels is not None: + blabels = [blank_labeler(label, value) for + label, value in zip(labels, y)] + else: + blabels = None results = ax.pie(y, labels=blabels, **kwds) if kwds.get('autopct', None) is not None: