8000 ENH: plot only numeric data and raise an exception *before* plotting if there is no numeric data by cpcloud · Pull Request #3572 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: plot only numeric data and raise an exception *before* plotting if there is no numeric data #3572

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

Merged
merged 2 commits into from
May 21, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
ENH/API: remove raise_on_error in plotting functions
trivial doc fix

note the docs

revert back
  • Loading branch information
cpcloud committed May 21, 2013
commit 1c8891e18597025764e810466c9c72c2e06a8907
10 changes: 7 additions & 3 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ pandas 0.11.1
thanks @hoechenberger
- ``read_html`` no longer performs hard date conversion
- Plotting functions now raise a ``TypeError`` before trying to plot anything
if the associated objects have have a dtype of ``object`` (GH1818_). This
happens before any drawing takes place which elimnates any spurious plots
from showing up.
if the associated objects have have a dtype of ``object`` (GH1818_,
GH3572_). This happens before any drawing takes place which elimnates any
spurious plots from showing up.

**API Changes**

Expand All @@ -93,6 +93,9 @@ pandas 0.11.1
- Raise on ``iloc`` when boolean indexing with a label based indexer mask
e.g. a boolean Series, even with integer labels, will raise. Since ``iloc``
is purely positional based, the labels on the Series are not alignable (GH3631_)
- The ``raise_on_error`` option to plotting methods is obviated by GH3572_,
so it is removed. Plots now always raise when data cannot be plotted or the
object being plotted has a dtype of ``object``.

**Bug Fixes**

Expand Down Expand Up @@ -232,6 +235,7 @@ pandas 0.11.1
.. _GH3649: https://github.com/pydata/pandas/issues/3649
.. _Gh3616: https://github.com/pydata/pandas/issues/3616
.. _GH1818: https://github.com/pydata/pandas/issues/1818
.. _GH3572: https://github.com/pydata/pandas/issues/3572

pandas 0.11.0
=============
Expand Down
15 changes: 11 additions & 4 deletions doc/source/v0.11.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ API changes

``df.iloc[mask]`` will raise a ``ValueError``

- The ``raise_on_error`` argument to plotting functions is removed. Instead,
plotting functions raise a ``TypeError`` when the ``dtype`` of the object
is ``object`` to remind you to avoid ``object`` arrays whenever possible
and thus you should cast to an appropriate numeric dtype if you need to
plot something.



Enhancements
Expand Down Expand Up @@ -119,7 +125,7 @@ Enhancements

The last element yielded by the iterator will be a ``Series`` containing
the last element of the longest string in the ``Series`` with all other
elements being ``NaN``. Here since ``'slow`` is the longest string
elements being ``NaN``. Here since ``'slow'`` is the longest string
and there are no other strings with the same length ``'w'`` is the only
non-null string in the yielded ``Series``.

Expand Down Expand Up @@ -160,9 +166,9 @@ Enhancements
to specify custom column names of the returned DataFrame.

- Plotting functions now raise a ``TypeError`` before trying to plot anything
if the associated objects have have a ``dtype`` of ``object`` (GH1818_).
This happens before any drawing takes place which elimnates any spurious
plots from showing up.
if the associated objects have have a ``dtype`` of ``object`` (GH1818_,
GH3572_). This happens before any drawing takes place which elimnates any
spurious plots from showing up.

Bug Fixes
~~~~~~~~~
Expand Down Expand Up @@ -234,3 +240,4 @@ on GitHub for a complete list.
.. _GH3606: https://github.com/pydata/pandas/issues/3606
.. _GH3656: https://github.com/pydata/pandas/issues/3656
.. _GH1818: https://github.com/pydata/pandas/issues/1818
.. _GH3572: https://github.com/pydata/pandas/issues/3572
60 changes: 19 additions & 41 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,8 @@ class MPLPlot(object):
"""
_default_rot = 0

_pop_attributes = ['label', 'style', 'logy', 'logx', 'loglog',
'raise_on_error']
_attr_defaults = {'logy': False, 'logx': False, 'loglog': False,
'raise_on_error': True}
_pop_attributes = ['label', 'style', 'logy', 'logx', 'loglog']
_attr_defaults = {'logy': False, 'logx': False, 'loglog': False}

def __init__(self, data, kind=None, by=None, subplots=False, sharex=True,
sharey=False, use_index=True,
Expand Down Expand Up @@ -1203,27 +1201,17 @@ def _make_plot(self):
else:
args = (ax, x, y, style)

try:
newline = plotf(*args, **kwds)[0]
lines.append(newline)
leg_label = label
if self.mark_right and self.on_right(i):
leg_label += ' (right)'
labels.append(leg_label)
ax.grid(self.grid)

if self._is_datetype():
left, right = _get_xlim(lines)
ax.set_xlim(left, right)
except AttributeError as inst: # non-numeric
msg = ('Unable to plot data %s vs index %s,\n'
'error was: %s' % (str(y), str(x), str(inst)))
if not self.raise_on_error:
print msg
else:
msg = msg + ('\nConsider setting raise_on_error=False'
'to suppress')
raise TypeError(msg)
newline = plotf(*args, **kwds)[0]
lines.append(newline)
leg_label = label
if self.mark_right and self.on_right(i):
leg_label += ' (right)'
labels.append(leg_label)
ax.grid(self.grid)

if self._is_datetype():
left, right = _get_xlim(lines)
ax.set_xlim(left, right)

self._make_legend(lines, labels)

Expand All @@ -1242,22 +1230,12 @@ def to_leg_label(label, i):
return label

def _plot(data, col_num, ax, label, style, **kwds):
try:
newlines = tsplot(data, plotf, ax=ax, label=label,
style=style, **kwds)
ax.grid(self.grid)
lines.append(newlines[0])
leg_label = to_leg_label(label, col_num)
labels.append(leg_label)
except AttributeError as inst: #non-numeric
msg = ('Unable to plot %s,\n'
'error was: %s' % (str(data), str(inst)))
if not self.raise_on_error:
print msg
else:
msg = msg + ('\nConsider setting raise_on_error=False'
'to suppress')
raise TypeError(msg)
newlines = tsplot(data, plotf, ax=ax, label=label,
style=style, **kwds)
ax.grid(self.grid)
lines.append(newlines[0])
leg_label = to_leg_label(label, col_num)
labels.append(leg_label)

if isinstance(data, Series):
ax = self._get_ax(0) # self.axes[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_nonnumeric_exclude(self):
df = DataFrame({'A': ["x", "y", "z"], 'B': [1,2,3]}, idx)

plt.close('all')
ax = df.plot(raise_on_error=False) # it works
ax = df.plot() # it works
self.assert_(len(ax.get_lines()) == 1) #B was plotted

plt.close('all')
Expand Down
0