Repository navigation
Raise TypeError for mapping-shaped cell_data instead of KeyError - #1575
Open
barlowa124 wants to merge 1 commit into
Open
barlowa124 wants to merge 1 commit into
barlowa124 wants to merge 1 commit into
Conversation
Mesh.__init__ indexes each cell_data value by position, so a nested
{cell type: {name: data}} dict crashed with KeyError: 0 when its
length happened to match the cell-block count. Reject mappings up
front with a message describing the expected
{name: [per-block arrays]} shape.
Fixes nschloe#1520.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1520.
meshio.Mesh(points, cells, cell_data=...)crashed withKeyError: 0when acell_datavalue was a nested dict ({cell_type: {name: data}}) instead of the documented{name: [per-block arrays]}shape.The validation loop checks
len(data) != len(cells)and then indexesdata[k]. A dict passes the length check whenever its key count happens to equal the block count, so the first subscript raisesKeyErrorwith no hint about the contract. The issue reporter hit exactly this with{"triangle": {"value": arr}}on a single triangle.This adds a
Mappingcheck at the top of the loop. That input now raisesTypeErrorbecause the signature already declaresdict[str, list[ArrayLike]], so a mapping value violates the declared contract. The neighboring shape mismatches remainValueError, matching the file's convention for value-level problems.Regression test in
tests/test_mesh.pycovers the reported shape. List and ndarray values are unaffected.pytest tests/test_mesh.pyreports 6 passed, 1 skipped.