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

Skip to content

Fixed deprecated APIs in lines.py #26902

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 1 commit into from
Sep 27, 2023
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/26902-RP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``Line2D``
~~~~~~~~~~

When creating a Line2D or using `.Line2D.set_xdata` and `.Line2D.set_ydata`,
passing x/y data as non sequence is now an error.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
passing x/y data as non sequence is now an error.
passing x/y data as non sequence is now an error.

This should fix pre-commit ci, which is complaining about the end of the file here

18 changes: 2 additions & 16 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,14 +1276,7 @@ def set_xdata(self, x):
x : 1D array
"""
if not np.iterable(x):
# 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, ]
raise RuntimeError('x must be a sequence')
self._xorig = copy.copy(x)
self._invalidx = True
self.stale = True
Expand All @@ -1297,14 +1290,7 @@ def set_ydata(self, y):
y : 1D array
"""
if not np.iterable(y):
# 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, ]
raise RuntimeError('y must be a sequence')
self._yorig = copy.copy(y)
self._invalidy = True
self.stale = True
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ def test_invalid_line_data():
mlines.Line2D([], 1)

line = mlines.Line2D([], [])
# when deprecation cycle is completed
# with pytest.raises(RuntimeError, match='x must be'):
with pytest.warns(mpl.MatplotlibDeprecationWarning):
with pytest.raises(RuntimeError, match='x must be'):
line.set_xdata(0)
# with pytest.raises(RuntimeError, match='y must be'):
with pytest.warns(mpl.MatplotlibDeprecationWarning):
with pytest.raises(RuntimeError, match='y must be'):
line.set_ydata(0)


Expand Down