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

Skip to content

Fix Poly3DCollection ragged padding overflow warnings - #32310

Open
ShamikOfficial wants to merge 1 commit into
matplotlib:mainfrom
ShamikOfficial:fix/poly3d-ragged-nan-padding
Open

Fix Poly3DCollection ragged padding overflow warnings#32310
ShamikOfficial wants to merge 1 commit into
matplotlib:mainfrom
ShamikOfficial:fix/poly3d-ragged-nan-padding

Conversation

@ShamikOfficial

Copy link
Copy Markdown

PR summary

When Poly3DCollection gets polygons with different vertex counts, _get_vector packs them into a rectangular array with np.empty(). Unused padding is marked in _invalid_vertices, but do_3d_projection still projects the whole array first. Uninitialized padding can hold huge float values and trigger nondeterministic RuntimeWarning: overflow encountered in dot.

This change initializes that padded storage with np.nan instead. NaN values do not overflow in the projection math, and do_3d_projection already ignores invalid floating point results. A regression test builds a square plus triangle collection, checks that padding is NaN, and draws under np.errstate(over="raise").

Closes #32272

Note: #32279 proposed the same fix earlier and was closed because of the automated-contribution account policy, not because the change itself was wrong.

AI Disclosure

I used Cursor to help locate the np.empty padding path, draft the regression test, and prepare the PR text. I reviewed the code path in Poly3DCollection._get_vector / do_3d_projection, confirmed why #32279 was closed, and verified the overflow reproduction plus the NaN-padding behavior locally before opening this PR.

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

Initialize padded vertex storage with NaN instead of empty so unused entries cannot overflow during projection before invalid masking.

Co-authored-by: Cursor <[email protected]>
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]: Ragged Poly3DCollection projects uninitialized padding, causing nondeterministic overflow

2 participants