From 7ad311bbb737036b1553d7b80fda7e276d4b87f6 Mon Sep 17 00:00:00 2001 From: heath Date: Tue, 9 Apr 2019 10:37:58 -0400 Subject: [PATCH] Implemented dropna bug fix for plt.hist --- seaborn/axisgrid.py | 9 +++++++++ seaborn/tests/test_axisgrid.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/seaborn/axisgrid.py b/seaborn/axisgrid.py index 6caf66b38a..8b518e2833 100644 --- a/seaborn/axisgrid.py +++ b/seaborn/axisgrid.py @@ -1273,6 +1273,9 @@ def __init__(self, data, hue=None, hue_order=None, palette=None, self.axes = axes self.data = data + # Save dropna variable to dictate filtering steps when plotting + self._dropna = dropna + # Save what we are going to do with the diagonal self.diag_sharey = diag_sharey self.diag_axes = None @@ -1391,6 +1394,12 @@ def map_diag(self, func, **kwargs): except KeyError: data_k = np.array([]) + if self._dropna: + data_k = utils.remove_na(data_k) + else: + if np.sum(np.isnan(data_k), axis=0).sum() > 0: + raise ValueError("Cannot plot histograms for data containing NAs. Please filter out NAs or pass `dropna=True`.") + if fixed_color is None: color = self.palette[k] else: diff --git a/seaborn/tests/test_axisgrid.py b/seaborn/tests/test_axisgrid.py index c7e182424b..d4736406ef 100644 --- a/seaborn/tests/test_axisgrid.py +++ b/seaborn/tests/test_axisgrid.py @@ -924,6 +924,13 @@ def test_map_diag(self): for ptch in ax.patches: nt.assert_equal(ptch.fill, False) + na_df = self.df.copy() + for i, var in enumerate(self.df.columns.values): + na_df.iloc[np.random.randint(len(na_df)), i] = np.nan + + g5 = ag.PairGrid(na_df, dropna=True) + g5.map_diag(plt.hist) + def test_map_diag_color(self): color = "red"