Skip to content

Commit 16edaaf

Browse files
bharatr21jreback
authored andcommitted
BUG: Fix #25481 by fixing the error message in TypeError (#25540)
1 parent 8117460 commit 16edaaf

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Performance Improvements
121121
Bug Fixes
122122
~~~~~~~~~
123123
- Bug in :func:`to_datetime` which would raise an (incorrect) ``ValueError`` when called with a date far into the future and the ``format`` argument specified instead of raising ``OutOfBoundsDatetime`` (:issue:`23830`)
124-
-
124+
- Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`)
125125
-
126126

127127
Categorical

pandas/plotting/_core.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,9 @@ def _compute_plot_data(self):
361361
except AttributeError:
362362
is_empty = not len(numeric_data)
363363

364-
# no empty frames or series allowed
364+
# no non-numeric frames or series allowed
365365
if is_empty:
366-
raise TypeError('Empty {0!r}: no numeric data to '
367-
'plot'.format(numeric_data.__class__.__name__))
366+
raise TypeError('no numeric data to plot')
368367

369368
self.data = numeric_data
370369

pandas/tests/plotting/test_datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_nonnumeric_exclude(self):
9797
assert len(ax.get_lines()) == 1 # B was plotted
9898
self.plt.close(fig)
9999

100-
msg = "Empty 'DataFrame': no numeric data to plot"
100+
msg = "no numeric data to plot"
101101
with pytest.raises(TypeError, match=msg):
102102
df['A'].plot()
103103

pandas/tests/plotting/test_frame.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ def test_subplots_timeseries_y_axis(self):
485485
ax_datetime_all_tz = testdata.plot(y="datetime_all_tz")
486486
assert (ax_datetime_all_tz.get_lines()[0].get_data()[1] ==
487487
testdata["datetime_all_tz"].values).all()
488-
with pytest.raises(TypeError):
488+
489+
msg = "no numeric data to plot"
490+
with pytest.raises(TypeError, match=msg):
489491
testdata.plot(y="text")
490492

491493
@pytest.mark.xfail(reason='not support for period, categorical, '
@@ -2219,7 +2221,9 @@ def test_all_invalid_plot_data(self):
22192221
for kind in plotting._core._common_kinds:
22202222
if not _ok_for_gaussian_kde(kind):
22212223
continue
2222-
with pytest.raises(TypeError):
2224+
2225+
msg = "no numeric data to plot"
2226+
with pytest.raises(TypeError, match=msg):
22232227
df.plot(kind=kind)
22242228

22252229
@pytest.mark.slow
@@ -2230,7 +2234,9 @@ def test_partially_invalid_plot_data(self):
22302234
for kind in plotting._core._common_kinds:
22312235
if not _ok_for_gaussian_kde(kind):
22322236
continue
2233-
with pytest.raises(TypeError):
2237+
2238+
msg = "no numeric data to plot"
2239+
with pytest.raises(TypeError, match=msg):
22342240
df.plot(kind=kind)
22352241

22362242
with tm.RNGContext(42):

pandas/tests/plotting/test_series.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ def test_invalid_plot_data(self):
706706
for kind in plotting._core._common_kinds:
707707
if not _ok_for_gaussian_kde(kind):
708708
continue
709-
with pytest.raises(TypeError):
709+
710+
msg = "no numeric data to plot"
711+
with pytest.raises(TypeError, match=msg):
710712
s.plot(kind=kind, ax=ax)
711713

712714
@pytest.mark.slow
@@ -723,7 +725,9 @@ def test_partially_invalid_plot_data(self):
723725
for kind in plotting._core._common_kinds:
724726
if not _ok_for_gaussian_kde(kind):
725727
continue
726-
with pytest.raises(TypeError):
728+
729+
msg = "no numeric data to plot"
730+
with pytest.raises(TypeError, match=msg):
727731
s.plot(kind=kind, ax=ax)
728732

729733
def test_invalid_kind(self):

0 commit comments

Comments
 (0)