Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix #25481 by fixing the error message in TypeError #25540

Merged
merged 5 commits into from
Mar 10, 2019
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Performance Improvements
Bug Fixes
~~~~~~~~~
- 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`)
-
- Bug in an error message in :meth:`DataFrame.plot`. Improved the error message if non-numerics are passed to :meth:`DataFrame.plot` (:issue:`25481`)
-

Categorical
Expand Down
5 changes: 2 additions & 3 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,9 @@ def _compute_plot_data(self):
except AttributeError:
is_empty = not len(numeric_data)

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

self.data = numeric_data

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_nonnumeric_exclude(self):
assert len(ax.get_lines()) == 1 # B was plotted
self.plt.close(fig)

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

Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def test_subplots_timeseries_y_axis(self):
ax_datetime_all_tz = testdata.plot(y="datetime_all_tz")
assert (ax_datetime_all_tz.get_lines()[0].get_data()[1] ==
testdata["datetime_all_tz"].values).all()
with pytest.raises(TypeError):

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
testdata.plot(y="text")

@pytest.mark.xfail(reason='not support for period, categorical, '
Expand Down Expand Up @@ -2219,7 +2221,9 @@ def test_all_invalid_plot_data(self):
for kind in plotting._core._common_kinds:
if not _ok_for_gaussian_kde(kind):
continue
with pytest.raises(TypeError):

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
df.plot(kind=kind)

@pytest.mark.slow
Expand All @@ -2230,7 +2234,9 @@ def test_partially_invalid_plot_data(self):
for kind in plotting._core._common_kinds:
if not _ok_for_gaussian_kde(kind):
continue
with pytest.raises(TypeError):

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
df.plot(kind=kind)

with tm.RNGContext(42):
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ def test_invalid_plot_data(self):
for kind in plotting._core._common_kinds:
if not _ok_for_gaussian_kde(kind):
continue
with pytest.raises(TypeError):

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
s.plot(kind=kind, ax=ax)

@pytest.mark.slow
Expand All @@ -711,7 +713,9 @@ def test_partially_invalid_plot_data(self):
for kind in plotting._core._common_kinds:
if not _ok_for_gaussian_kde(kind):
continue
with pytest.raises(TypeError):

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
s.plot(kind=kind, ax=ax)

def test_invalid_kind(self):
Expand Down