Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit545b581

Browse files
authored
Merge pull request#25196 from ericpre/add_deprecation_sequence_set_data_line
Add deprecation for setting data with non sequence type in `Line2D`
2 parents81f5f24 +044fbc0 commit545b581

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``Line2D``
2+
~~~~~~~~~~
3+
When creating a Line2D or using `.Line2D.set_xdata` and `.Line2D.set_ydata`,
4+
passing x/y data as non sequence is deprecated.

‎lib/matplotlib/lines.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,14 @@ def set_xdata(self, x):
12801280
x : 1D array
12811281
"""
12821282
ifnotnp.iterable(x):
1283-
raiseRuntimeError('x must be a sequence')
1283+
# When deprecation cycle is completed
1284+
# raise RuntimeError('x must be a sequence')
1285+
_api.warn_deprecated(
1286+
since=3.7,
1287+
message="Setting data with a non sequence type "
1288+
"is deprecated since %(since)s and will be "
1289+
"remove %(removal)s")
1290+
x= [x, ]
12841291
self._xorig=copy.copy(x)
12851292
self._invalidx=True
12861293
self.stale=True
@@ -1294,7 +1301,14 @@ def set_ydata(self, y):
12941301
y : 1D array
12951302
"""
12961303
ifnotnp.iterable(y):
1297-
raiseRuntimeError('y must be a sequence')
1304+
# When deprecation cycle is completed
1305+
# raise RuntimeError('y must be a sequence')
1306+
_api.warn_deprecated(
1307+
since=3.7,
1308+
message="Setting data with a non sequence type "
1309+
"is deprecated since %(since)s and will be "
1310+
"remove %(removal)s")
1311+
y= [y, ]
12981312
self._yorig=copy.copy(y)
12991313
self._invalidy=True
13001314
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
importmatplotlib.pyplotasplt
2121
importmatplotlib.transformsasmtransforms
2222
frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal
23+
frommatplotlib._api.deprecationimportMatplotlibDeprecationWarning
2324

2425

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

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

99103

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp