Skip to content

fix(graphics): accept unspecified dimensions in expand_dims - #270

Open
Doribelove wants to merge 2 commits into
rai-opensource:masterfrom
Doribelove:fix/expand-dims-unspecified
Open

Doribelove wants to merge 2 commits into
rai-opensource:masterfrom
Doribelove:fix/expand-dims-unspecified

Conversation

@Doribelove

@Doribelove Doribelove commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #261.

expand_dims() raises TypeError even though dim=None is its documented default. Return None for an unspecified extent so callers can choose autoscaling or obtain limits elsewhere. Update the argument and return annotations and docstring to describe this behavior.

Validate nd before returning, so unsupported dimensions still raise ValueError, including when dim is None; zero remains an explicit extent. Add regressions for omitted and explicit None in 2D/3D, explicit numeric extents, malformed vectors, and unsupported dimensions. Preserve the negative-scalar and reversed-limit behavior from #262 and its regression tests.

Validation on this branch including upstream master 824a459 (MPLBACKEND=Agg):

  • Python 3.12.14 full suite: 476 passed, 3 skipped, with 71 subtests passed and 23 warnings.
  • Graphics tests on Python 3.10.12 and 3.12.14: 21 passed, with 8 subtests passed on each version.
  • Repository pre-commit hooks (Black 23.10.0, EOF, debug statements, trailing whitespace) and git diff --check pass. Black also wraps existing long lines in the touched graphics module and test file.

The existing internal callers already guard None. Downstream bdsim behavior has not been tested; the scale=None timing change noted in #261 remains applicable.

Signed-off-by: 李永祺 <doribelove@gmail.com>
@petercorke

Copy link
Copy Markdown
Collaborator

Thanks Dori, and thanks for the clear write-up. This is a nice tidy fix for #261.

I merged it with current master locally and the full suite passes (413 passed, 3 skipped). I also checked the four internal callers (plotvol2, plotvol3, Animate, and the dims handling in transforms2d.py). Each one tests for None before calling, so nothing changes for them, and I'm happy to leave them as they are.

Checking nd before the None return is a good catch, as is the 0 test showing it's treated as an explicit extent. Approving.

(Optional, not blocking: the Black re-wrap in _axes_dimensions is unrelated to this fix. It's fine to keep.)

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: 李永祺 <doribelove@gmail.com>
@Doribelove

Copy link
Copy Markdown
Contributor Author

Merged current master 824a459 into this branch in d86d08c to resolve the test insertion conflict after #262. Both sets of regression tests are retained, including the negative-scalar and reversed-limit cases; their behavior is unchanged.

With MPLBACKEND=Agg, the full suite on Python 3.12.14 passes with 476 passed, 3 skipped (71 subtests passed). The graphics tests pass on Python 3.10.12 and 3.12.14 with 21 passed and 8 subtests on each. The configured pre-commit hooks and git diff --check also pass. The PR description now reflects the updated branch and validation.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expand_dims(None) raises TypeError although None is its documented default

3 participants