Skip to content

Commit e226bac

Browse files
author
Tom Augspurger
committed
Merge pull request #8196 from onesandzeroes/kde-na
API: kdeplot fails with NaNs.
2 parents 01e1856 + 958a99e commit e226bac

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

doc/source/v0.15.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,5 @@ Bug Fixes
667667

668668
- Bug in accessing groups from a ``GroupBy`` when the original grouper
669669
was a tuple (:issue:`8121`).
670+
671+
- Bug with kde plot and NaNs (:issue:`8182`)

pandas/tests/test_graphics.py

+16
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,14 @@ def test_kde_kwargs(self):
745745
self._check_ax_scales(ax, yaxis='log')
746746
self._check_text_labels(ax.yaxis.get_label(), 'Density')
747747

748+
@slow
749+
def test_kde_missing_vals(self):
750+
tm._skip_if_no_scipy()
751+
_skip_if_no_scipy_gaussian_kde()
752+
s = Series(np.random.uniform(size=50))
753+
s[0] = np.nan
754+
ax = _check_plot_works(s.plot, kind='kde')
755+
748756
@slow
749757
def test_hist_kwargs(self):
750758
ax = self.ts.plot(kind='hist', bins=5)
@@ -1876,6 +1884,14 @@ def test_kde_df(self):
18761884
axes = df.plot(kind='kde', logy=True, subplots=True)
18771885
self._check_ax_scales(axes, yaxis='log')
18781886

1887+
@slow
1888+
def test_kde_missing_vals(self):
1889+
tm._skip_if_no_scipy()
1890+
_skip_if_no_scipy_gaussian_kde()
1891+
df = DataFrame(np.random.uniform(size=(100, 4)))
1892+
df.loc[0, 0] = np.nan
1893+
ax = _check_plot_works(df.plot, kind='kde')
1894+
18791895
@slow
18801896
def test_hist_df(self):
18811897
df = DataFrame(randn(100, 4))

pandas/tools/plotting.py

+1
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ def _get_plot_function(self):
19541954
from scipy import __version__ as spv
19551955
f = MPLPlot._get_plot_function(self)
19561956
def plotf(ax, y, style=None, column_num=None, **kwds):
1957+
y = remove_na(y)
19571958
if LooseVersion(spv) >= '0.11.0':
19581959
gkde = gaussian_kde(y, bw_method=self.bw_method)
19591960
else:

0 commit comments

Comments
 (0)