Skip to content

Better argspecs for Axes.stem #11271

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 23, 2018
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/2018-05-06-ZHD.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Consistent handling of \*args in Axes.stem
------------------------------------------

:meth:`matplotlib.axex.Axes.stem` now raises TypeError when passed
unhandled positional arguments. If two or more arguments are passed
(ie X, Y, [linefmt], ...) and Y cannot be cast to an array, an error
will be raised instead of treating X as Y and Y as linefmt.
12 changes: 7 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2350,17 +2350,19 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
which inspired this method.

"""
# Assume there's at least one data array
if not 1 <= len(args) <= 5:
raise TypeError('stem expected between 1 and 5 positional '
'arguments, got {}'.format(args))

y = np.asarray(args[0])
args = args[1:]

# Try a second one
try:
x, y = y, np.asarray(args[0], dtype=float)
except (IndexError, ValueError):
# The second array doesn't make sense, or it doesn't exist
if not args:
x = np.arange(len(y))
else:
x = y
y = np.asarray(args[0], dtype=float)
args = args[1:]

# defaults for formats
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def test_detrend_detrend_linear_1d_slope_off_axis1(self):
res = mlab.detrend(input, key=mlab.detrend_linear, axis=0)
assert_allclose(res, targ, atol=self.atol)

def test_detrend_str_linear_2d_slope_off_axis0(self):
def test_detrend_str_linear_2d_slope_off_axis0_notranspose(self):
arri = [self.sig_off,
self.sig_slope,
self.sig_slope + self.sig_off]
Expand All @@ -1131,7 +1131,7 @@ def test_detrend_str_linear_2d_slope_off_axis0(self):
res = mlab.detrend(input, key='linear', axis=1)
assert_allclose(res, targ, atol=self.atol)

def test_detrend_detrend_linear_1d_slope_off_axis1(self):
def test_detrend_detrend_linear_1d_slope_off_axis1_notranspose(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a particular need to change these test names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - there's another test with this name, so before renaming this test could never be run!

arri = [self.sig_off,
self.sig_slope,
self.sig_slope + self.sig_off]
Expand Down