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

Skip to content

Fix Line3D.draw AttributeError for list coordinates with NaN - #32306

Open
ShamikOfficial wants to merge 3 commits into
matplotlib:mainfrom
ShamikOfficial:fix/line3d-set-data-3d-asarray
Open

Fix Line3D.draw AttributeError for list coordinates with NaN#32306
ShamikOfficial wants to merge 3 commits into
matplotlib:mainfrom
ShamikOfficial:fix/line3d-set-data-3d-asarray

Conversation

@ShamikOfficial

@ShamikOfficial ShamikOfficial commented Sep 5, 2026

Copy link
Copy Markdown

PR summary

Closes #32127.

Line3D.set_data_3d is documented to take array-like input and stores the values as given. draw then used self._verts3d[0].shape when applying the invalid-scale mask, so a plain Python list with a NaN raised AttributeError. Finite lists still drew, which is why this only shows up once a coordinate goes non-finite.

This PR changes that access to np.shape(self._verts3d[0]) so lists and tuples work. set_data_3d is left alone, so get_data_3d() still returns whatever was passed in.

Added a regression test for the reported case: lists containing NaN, then canvas.draw(), and an assert that get_data_3d() still returns the original lists.

AI Disclosure

Used Cursor to find the mplot3d code paths, draft the small patch/test, and help open the PR. Updated the approach to np.shape in draw based on review feedback on the issue. The summary above is written in my own words.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New features and API changes have release notes
  • [n/a] Documentation complies with general and docstring guidelines

set_data_3d documents array-like input but stored values verbatim, while
draw assumes .shape. Coerce with np.asarray so invalid-scale masking works.

Co-authored-by: Cursor <[email protected]>
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Comment thread lib/mpl_toolkits/mplot3d/art3d.py Outdated

@iccir iccir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything looks good except for the comment!

Comment thread lib/mpl_toolkits/mplot3d/art3d.py Outdated
@ShamikOfficial

Copy link
Copy Markdown
Author

Thanks @scottshambaugh. Dropped the comment.

@iccir
iccir self-requested a review September 7, 2026 03:48
Keep set_data_3d storing inputs as given so get_data_3d behavior is unchanged, and make draw tolerate lists/tuples when masking invalid scale values.

Co-authored-by: Cursor <[email protected]>
@ShamikOfficial

Copy link
Copy Markdown
Author

Updated per feedback on #32127: switched from coercing in set_data_3d to using np.shape(self._verts3d[0]) in draw.

This keeps get_data_3d() returning what was passed in, while still fixing the AttributeError for list/tuple coordinates with non-finite values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Line3D.draw requires .shape on _verts3d, but set_data_3d accepts and stores any array-like

3 participants