Fix Line3D.draw AttributeError for list coordinates with NaN by ShamikOfficial · Pull Request #32306 · matplotlib/matplotlib · GitHub
Skip to content

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

Open
ShamikOfficial wants to merge 1 commit 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 1 commit 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, but it stored the values as given. draw then does self._verts3d[0].shape when applying the invalid-scale mask, so a plain Python list with a NaN raises AttributeError. Finite lists still drew, which is why this only shows up once a coordinate goes non-finite.

I fixed it in the setter by coercing each coordinate with np.asarray. That keeps draw unchanged and makes _verts3d consistently arrays. The other option is np.shape(...) in draw, which would preserve the original list/tuple type from get_data_3d(). I preferred normalizing at the setter because the draw path already treats these as arrays, and reading the data back still compares equal under np.testing.assert_array_equal (covered by the existing set/get test).

Added a regression test for the reported case: lists containing NaN, then canvas.draw().

AI Disclosure

Used Cursor to find the mplot3d code paths, draft the small patch/test, and help open the PR. I chose coercion in set_data_3d over np.shape in draw after reading the discussion on the earlier closed attempt (#32128). 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 <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

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.

I think we can drop the comment, but this PR lgtm

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

2 participants