diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 90297ecfa3415..fed4b0d90983c 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -2426,6 +2426,10 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None, data = data._get_numeric_data() naxes = len(data.columns) + if naxes == 0: + raise ValueError("hist method requires numerical columns, " + "nothing to plot.") + fig, axes = _subplots(naxes=naxes, ax=ax, squeeze=False, sharex=sharex, sharey=sharey, figsize=figsize, layout=layout) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index c62ed21c2fb17..f3f6c9c7fc2d4 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -209,6 +209,16 @@ def test_hist_df_legacy(self): with pytest.raises(AttributeError): ser.hist(foo='bar') + @pytest.mark.slow + def test_hist_non_numerical_raises(self): + # gh-10444 + df = DataFrame(np.random.rand(10, 2)) + df_o = df.astype(np.object) + + msg = "hist method requires numerical columns, nothing to plot." + with pytest.raises(ValueError, match=msg): + df_o.hist() + @pytest.mark.slow def test_hist_layout(self): df = DataFrame(randn(100, 3))