Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e880c4

Browse files
committed
Add deprecation for setting data with non sequence type in Line2D - see #22329
1 parent 73909bc commit 9e880c4

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/matplotlib/lines.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,14 @@ def set_xdata(self, x):
12741274
x : 1D array
12751275
"""
12761276
if not np.iterable(x):
1277-
raise RuntimeError('x must be a sequence')
1277+
# When deprecation cycle is completed
1278+
# raise RuntimeError('x must be a sequence')
1279+
_api.warn_deprecated(
1280+
since=3.7,
1281+
message="Setting data with a non sequence type "
1282+
"is deprecated since %(since)s and will be "
1283+
"remove %(removal)s")
1284+
x = [x, ]
12781285
self._xorig = copy.copy(x)
12791286
self._invalidx = True
12801287
self.stale = True
@@ -1288,7 +1295,14 @@ def set_ydata(self, y):
12881295
y : 1D array
12891296
"""
12901297
if not np.iterable(y):
1291-
raise RuntimeError('y must be a sequence')
1298+
# When deprecation cycle is completed
1299+
# raise RuntimeError('y must be a sequence')
1300+
_api.warn_deprecated(
1301+
since=3.7,
1302+
message="Setting data with a non sequence type "
1303+
"is deprecated since %(since)s and will be "
1304+
"remove %(removal)s")
1305+
y = [y, ]
12921306
self._yorig = copy.copy(y)
12931307
self._invalidy = True
12941308
self.stale = True

lib/matplotlib/tests/test_lines.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import matplotlib.pyplot as plt
2121
import matplotlib.transforms as mtransforms
2222
from matplotlib.testing.decorators import image_comparison, check_figures_equal
23+
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
2324

2425

2526
def test_segment_hits():
@@ -91,9 +92,12 @@ def test_invalid_line_data():
9192
mlines.Line2D([], 1)
9293

9394
line = mlines.Line2D([], [])
94-
with pytest.raises(RuntimeError, match='x must be'):
95+
# when deprecation cycle is completed
96+
# with pytest.raises(RuntimeError, match='x must be'):
97+
with pytest.warns(MatplotlibDeprecationWarning):
9598
line.set_xdata(0)
96-
with pytest.raises(RuntimeError, match='y must be'):
99+
# with pytest.raises(RuntimeError, match='y must be'):
100+
with pytest.warns(MatplotlibDeprecationWarning):
97101
line.set_ydata(0)
98102

99103

0 commit comments

Comments
 (0)