Skip to content

Commit

Permalink
Implemented dropna bug fix for plt.hist
Browse files Browse the repository at this point in the history
  • Loading branch information
atheheath committed Apr 9, 2019
1 parent 36964d7 commit 7ad311b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions seaborn/tests/test_axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7ad311b

Please sign in to comment.