Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Bug Fixes

- Bug in plotting continuously using ``secondary_y`` may not show legend properly. (:issue:`9610`, :issue:`9779`)

- Bug in ``DataFrame.plot(kind="hist")`` results in ``TypeError`` when ``DataFrame`` contains non-numeric columns (:issue:`9853`)

- Bug in ``Series.quantile`` on empty Series of type ``Datetime`` or ``Timedelta`` (:issue:`9675`)
- Bug in ``where`` causing incorrect results when upcasting was required (:issue:`9731`)
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,18 @@ def test_hist_df_kwargs(self):
ax = df.plot(kind='hist', bins=5)
self.assertEqual(len(ax.patches), 10)

@slow
def test_hist_df_with_nonnumerics(self):
# GH 9853
with tm.RNGContext(1):
df = DataFrame(np.random.randn(10, 4), columns=['A', 'B', 'C', 'D'])
df['E'] = ['x', 'y'] * 5
ax = df.plot(kind='hist', bins=5)
self.assertEqual(len(ax.patches), 20)

ax = df.plot(kind='hist') # bins=10
self.assertEqual(len(ax.patches), 40)

@slow
def test_hist_legacy(self):
_check_plot_works(self.ts.hist)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,8 @@ def __init__(self, data, bins=10, bottom=0, **kwargs):
def _args_adjust(self):
if com.is_integer(self.bins):
# create common bin edge
values = np.ravel(self.data.values)
values = self.data.convert_objects()._get_numeric_data()
values = np.ravel(values)
values = values[~com.isnull(values)]

hist, self.bins = np.histogram(values, bins=self.bins,
Expand Down