From 45a99ec9ecf4b45ed911e1becc33402e30152fe9 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Wed, 7 Dec 2016 20:19:48 -0500 Subject: [PATCH 1/7] fixed kde plot to ignore the missing values --- pandas/tools/plotting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index d46dc4d355b4c..ae9a0e2da9382 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -2136,9 +2136,9 @@ def _args_adjust(self): 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) + 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 From 101b0d475a36a7776f26acbe7b86526be9947e24 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Wed, 7 Dec 2016 20:43:46 -0500 Subject: [PATCH 2/7] added comment to elaborate the changes made --- pandas/tools/plotting.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index ae9a0e2da9382..484270ecbda0b 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -2136,6 +2136,7 @@ def _args_adjust(self): def _get_ind(self, y): if self.ind is None: + # 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) From d2657e3e57b67e30245ad38efc5ced2dc0a3a117 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Thu, 8 Dec 2016 12:05:23 -0500 Subject: [PATCH 3/7] added a release note in whatsnew/0.19.2 --- doc/source/whatsnew/v0.19.2.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index 0567a3c3fa2bb..2961249504f97 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -76,3 +76,5 @@ 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`) \ No newline at end of file From 59db2c68b61df27a868c34793c44e8ca9597fcd4 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 11 Dec 2016 11:51:24 -0500 Subject: [PATCH 4/7] added test to check for missing values and cleaned up whatsnew doc --- doc/source/whatsnew/v0.19.2.txt | 4 +--- pandas/tests/plotting/test_series.py | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index 502097f7c0fb2..05bce0e5c8849 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -78,8 +78,6 @@ Bug Fixes - Explicit check in ``to_stata`` and ``StataWriter`` for out-of-range values when writing doubles (:issue:`14618`) -<<<<<<< HEAD - 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`) ->>>>>>> master diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index e752197c6ad77..f28bd22db45a8 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -2,6 +2,7 @@ # coding: utf-8 import nose +import math import itertools from datetime import datetime @@ -569,7 +570,9 @@ def test_kde_missing_vals(self): _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 + self.assertTrue(any(~np.isnan(axes.lines[0]._xorig)), msg='Missing Values not dropped') @slow def test_hist_kwargs(self): From e9f67e339d6ba95397c0cc4076d62ee8d1ed4f6e Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 11 Dec 2016 11:58:06 -0500 Subject: [PATCH 5/7] added comment to refer the issue --- pandas/tests/plotting/test_series.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index f28bd22db45a8..e7fe46404df0b 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -572,6 +572,7 @@ def test_kde_missing_vals(self): s[0] = np.nan axes = _check_plot_works(s.plot.kde) #check if the values have any missing values + #GH14821 self.assertTrue(any(~np.isnan(axes.lines[0]._xorig)), msg='Missing Values not dropped') @slow From 613cd724c5ec56f734b3b8da26dfba7ec1e94cc3 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 11 Dec 2016 14:38:07 -0500 Subject: [PATCH 6/7] modified to fit lint checks --- pandas/tests/plotting/test_series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index e7fe46404df0b..572119396d351 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -2,7 +2,6 @@ # coding: utf-8 import nose -import math import itertools from datetime import datetime @@ -571,9 +570,10 @@ def test_kde_missing_vals(self): s = Series(np.random.uniform(size=50)) s[0] = np.nan axes = _check_plot_works(s.plot.kde) - #check if the values have any missing values - #GH14821 - self.assertTrue(any(~np.isnan(axes.lines[0]._xorig)), msg='Missing Values not dropped') + # check if the values have any missing values + # GH14821 + self.assertTrue(any(~np.isnan(axes.lines[0]._xorig)), + msg='Missing Values not dropped') @slow def test_hist_kwargs(self): From 4273f8e9f53d49988fcdefc2e5afb61e9bdc57ff Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Wed, 14 Dec 2016 15:22:16 -0500 Subject: [PATCH 7/7] replaced ._xorig with .get_xdata() --- pandas/tests/plotting/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 572119396d351..73119fec88198 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -572,7 +572,7 @@ def test_kde_missing_vals(self): axes = _check_plot_works(s.plot.kde) # check if the values have any missing values # GH14821 - self.assertTrue(any(~np.isnan(axes.lines[0]._xorig)), + self.assertTrue(any(~np.isnan(axes.lines[0].get_xdata())), msg='Missing Values not dropped') @slow