From ad389f6f2bcf7bdf1956baadd9e7593a8e1fc9a8 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sun, 6 May 2018 19:50:09 +1000 Subject: [PATCH 1/2] Consistent handling of *args in Axes.stem --- doc/api/next_api_changes/2018-05-06-ZHD.rst | 7 +++++++ lib/matplotlib/axes/_axes.py | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 doc/api/next_api_changes/2018-05-06-ZHD.rst diff --git a/doc/api/next_api_changes/2018-05-06-ZHD.rst b/doc/api/next_api_changes/2018-05-06-ZHD.rst new file mode 100644 index 000000000000..61a8886c4890 --- /dev/null +++ b/doc/api/next_api_changes/2018-05-06-ZHD.rst @@ -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. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d6e4f50a2d7e..4e7551872882 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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 From 51a93f0f0b5bf286160c2f7d5a6c1c9c47e83f81 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 19 May 2018 00:06:23 +1000 Subject: [PATCH 2/2] De-duplicate test names --- lib/matplotlib/tests/test_mlab.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_mlab.py b/lib/matplotlib/tests/test_mlab.py index d336fea01ff7..cd2c54b71b25 100644 --- a/lib/matplotlib/tests/test_mlab.py +++ b/lib/matplotlib/tests/test_mlab.py @@ -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] @@ -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): arri = [self.sig_off, self.sig_slope, self.sig_slope + self.sig_off] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy