From 9e880c4d7b81d53a5a2494956ffdfe03f507e730 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sat, 11 Feb 2023 11:33:37 +0000 Subject: [PATCH 1/2] Add deprecation for setting data with non sequence type in `Line2D` - see https://github.com/matplotlib/matplotlib/pull/22329 --- lib/matplotlib/lines.py | 18 ++++++++++++++++-- lib/matplotlib/tests/test_lines.py | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index ef92b975b21d..53bffcc30a39 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -1274,7 +1274,14 @@ def set_xdata(self, x): x : 1D array """ if not np.iterable(x): - raise RuntimeError('x must be a sequence') + # When deprecation cycle is completed + # raise RuntimeError('x must be a sequence') + _api.warn_deprecated( + since=3.7, + message="Setting data with a non sequence type " + "is deprecated since %(since)s and will be " + "remove %(removal)s") + x = [x, ] self._xorig = copy.copy(x) self._invalidx = True self.stale = True @@ -1288,7 +1295,14 @@ def set_ydata(self, y): y : 1D array """ if not np.iterable(y): - raise RuntimeError('y must be a sequence') + # When deprecation cycle is completed + # raise RuntimeError('y must be a sequence') + _api.warn_deprecated( + since=3.7, + message="Setting data with a non sequence type " + "is deprecated since %(since)s and will be " + "remove %(removal)s") + y = [y, ] self._yorig = copy.copy(y) self._invalidy = True self.stale = True diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index 1f25b84d8081..7eecf5675a4b 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -20,6 +20,7 @@ import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms from matplotlib.testing.decorators import image_comparison, check_figures_equal +from matplotlib._api.deprecation import MatplotlibDeprecationWarning def test_segment_hits(): @@ -91,9 +92,12 @@ def test_invalid_line_data(): mlines.Line2D([], 1) line = mlines.Line2D([], []) - with pytest.raises(RuntimeError, match='x must be'): + # when deprecation cycle is completed + # with pytest.raises(RuntimeError, match='x must be'): + with pytest.warns(MatplotlibDeprecationWarning): line.set_xdata(0) - with pytest.raises(RuntimeError, match='y must be'): + # with pytest.raises(RuntimeError, match='y must be'): + with pytest.warns(MatplotlibDeprecationWarning): line.set_ydata(0) From 044fbc01490ce1c76982310060c18c7b15035fa5 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sat, 11 Feb 2023 11:51:59 +0000 Subject: [PATCH 2/2] Add changelog note --- doc/api/next_api_changes/deprecations/25196-EP.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/api/next_api_changes/deprecations/25196-EP.rst diff --git a/doc/api/next_api_changes/deprecations/25196-EP.rst b/doc/api/next_api_changes/deprecations/25196-EP.rst new file mode 100644 index 000000000000..99f55401976d --- /dev/null +++ b/doc/api/next_api_changes/deprecations/25196-EP.rst @@ -0,0 +1,4 @@ +``Line2D`` +~~~~~~~~~~ +When creating a Line2D or using `.Line2D.set_xdata` and `.Line2D.set_ydata`, +passing x/y data as non sequence is deprecated. 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