Fixed KDE Plot to drop the missing values (#14820)
BUG: Fixed KDE plot to ignore missing values
closes #14821
* fixed kde plot to ignore the missing values
* added comment to elaborate the changes made
* added a release note in whatsnew/0.19.2
* added test to check for missing values and cleaned up whatsnew doc
* added comment to refer the issue
* modified to fit lint checks
* replaced ._xorig with .get_xdata()
(cherry picked from commit 033d34596f
)
This commit is contained in:
parent
9a6a78f36b
commit
435947134c
|
@ -88,4 +88,6 @@ Bug Fixes
|
|||
|
||||
- Explicit check in ``to_stata`` and ``StataWriter`` for out-of-range values when writing doubles (:issue:`14618`)
|
||||
|
||||
- Bug in ``.plot(kind='kde')`` which did not drop missing values to generate the KDE Plot, instead generating an empty plot. (:issue:`14821`)
|
||||
|
||||
- Bug in ``unstack()`` if called with a list of column(s) as an argument, regardless of the dtypes of all columns, they get coerced to ``object`` (:issue:`11847`)
|
||||
|
|
|
@ -569,7 +569,11 @@ class TestSeriesPlots(TestPlotBase):
|
|||
_skip_if_no_scipy_gaussian_kde()
|
||||
s = Series(np.random.uniform(size=50))
|
||||
s[0] = np.nan
|
||||
_check_plot_works(s.plot.kde)
|
||||
axes = _check_plot_works(s.plot.kde)
|
||||
# check if the values have any missing values
|
||||
# GH14821
|
||||
self.assertTrue(any(~np.isnan(axes.lines[0].get_xdata())),
|
||||
msg='Missing Values not dropped')
|
||||
|
||||
@slow
|
||||
def test_hist_kwargs(self):
|
||||
|
|
|
@ -2136,9 +2136,10 @@ class KdePlot(HistPlot):
|
|||
|
||||
def _get_ind(self, y):
|
||||
if self.ind is None:
|
||||
sample_range = max(y) - min(y)
|
||||
ind = np.linspace(min(y) - 0.5 * sample_range,
|
||||
max(y) + 0.5 * sample_range, 1000)
|
||||
# np.nanmax() and np.nanmin() ignores the missing values
|
||||
sample_range = np.nanmax(y) - np.nanmin(y)
|
||||
ind = np.linspace(np.nanmin(y) - 0.5 * sample_range,
|
||||
np.nanmax(y) + 0.5 * sample_range, 1000)
|
||||
else:
|
||||
ind = self.ind
|
||||
return ind
|
||||
|
|
Loading…
Reference in New Issue