Skip to content

Commit 5bbba11

Browse files
committed
Fix for handling both ndarray and series.
Also fix if NaN's make an entire group empty
1 parent 20a02c3 commit 5bbba11

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pandas/tools/plotting.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,15 +2947,22 @@ def grouped_hist(data, column=None, weights=None, by=None, ax=None, bins=50,
29472947
axes: collection of Matplotlib Axes
29482948
"""
29492949
def plot_group(group, ax, weights=None):
2950+
if isinstance(group, np.ndarray) == False:
2951+
group = group.values
29502952
if weights is not None:
29512953
# remove fields where we have nan in weights OR in group
29522954
# for both data sets
2955+
if isinstance(weights, np.ndarray) == False:
2956+
weights = weights.values
29532957
inx_na = (np.isnan(weights)) | (np.isnan(group))
2954-
weights = weights.ix[~inx_na]
2955-
group = group.ix[~inx_na]
2958+
weights = weights[~inx_na]
2959+
group = group[~inx_na]
29562960
else:
29572961
group = group.dropna()
2958-
ax.hist(group.values, weights=weights.values, bins=bins, **kwargs)
2962+
if len(group) > 0:
2963+
# if length is less than 0, we had only NaN's for this group
2964+
# nothing to print!
2965+
ax.hist(group, weights=weights, bins=bins, **kwargs)
29592966

29602967
xrot = xrot or rot
29612968

0 commit comments

Comments
 (0)