diff --git a/doc/source/v0.15.0.txt b/doc/source/v0.15.0.txt index 5a65d4305ec55..71f39d9621bee 100644 --- a/doc/source/v0.15.0.txt +++ b/doc/source/v0.15.0.txt @@ -667,3 +667,5 @@ Bug Fixes - Bug in accessing groups from a ``GroupBy`` when the original grouper was a tuple (:issue:`8121`). + +- Bug with kde plot and NaNs (:issue:`8182`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 7694b1b087d10..131edf499ff18 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -745,6 +745,14 @@ def test_kde_kwargs(self): self._check_ax_scales(ax, yaxis='log') self._check_text_labels(ax.yaxis.get_label(), 'Density') + @slow + def test_kde_missing_vals(self): + tm._skip_if_no_scipy() + _skip_if_no_scipy_gaussian_kde() + s = Series(np.random.uniform(size=50)) + s[0] = np.nan + ax = _check_plot_works(s.plot, kind='kde') + @slow def test_hist_kwargs(self): ax = self.ts.plot(kind='hist', bins=5) @@ -1876,6 +1884,14 @@ def test_kde_df(self): axes = df.plot(kind='kde', logy=True, subplots=True) self._check_ax_scales(axes, yaxis='log') + @slow + def test_kde_missing_vals(self): + tm._skip_if_no_scipy() + _skip_if_no_scipy_gaussian_kde() + df = DataFrame(np.random.uniform(size=(100, 4))) + df.loc[0, 0] = np.nan + ax = _check_plot_works(df.plot, kind='kde') + @slow def test_hist_df(self): df = DataFrame(randn(100, 4)) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 50f3ab23babad..56316ac726c8a 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1954,6 +1954,7 @@ def _get_plot_function(self): from scipy import __version__ as spv f = MPLPlot._get_plot_function(self) def plotf(ax, y, style=None, column_num=None, **kwds): + y = remove_na(y) if LooseVersion(spv) >= '0.11.0': gkde = gaussian_kde(y, bw_method=self.bw_method) else: