Skip to content

Commit a8af7a1

Browse files
matsmaiwaldanother-green
authored andcommitted
Better error message for DataFrame.hist() without numerical columns (… (pandas-dev#26483)
1 parent cffbaac commit a8af7a1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pandas/plotting/_core.py

+4
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,10 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
24262426
data = data._get_numeric_data()
24272427
naxes = len(data.columns)
24282428

2429+
if naxes == 0:
2430+
raise ValueError("hist method requires numerical columns, "
2431+
"nothing to plot.")
2432+
24292433
fig, axes = _subplots(naxes=naxes, ax=ax, squeeze=False,
24302434
sharex=sharex, sharey=sharey, figsize=figsize,
24312435
layout=layout)

pandas/tests/plotting/test_hist_method.py

+10
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ def test_hist_df_legacy(self):
209209
with pytest.raises(AttributeError):
210210
ser.hist(foo='bar')
211211

212+
@pytest.mark.slow
213+
def test_hist_non_numerical_raises(self):
214+
# gh-10444
215+
df = DataFrame(np.random.rand(10, 2))
216+
df_o = df.astype(np.object)
217+
218+
msg = "hist method requires numerical columns, nothing to plot."
219+
with pytest.raises(ValueError, match=msg):
220+
df_o.hist()
221+
212222
@pytest.mark.slow
213223
def test_hist_layout(self):
214224
df = DataFrame(randn(100, 3))

0 commit comments

Comments
 (0)