Skip to content

Fix selection slice from integer#784

Merged
nvlukasz merged 2 commits into
newton-physics:mainfrom
nvlukasz:fix-selection-slice
Sep 18, 2025
Merged

Fix selection slice from integer#784
nvlukasz merged 2 commits into
newton-physics:mainfrom
nvlukasz:fix-selection-slice

Conversation

@nvlukasz

@nvlukasz nvlukasz commented Sep 18, 2025

Copy link
Copy Markdown
Member

Fix ArticulationView.get_root_transforms() raising this error with fixed-base articulations:

  File "/home/antoiner/Documents/newton/newton/_src/utils/selection.py", line 523, in _get_attribute_array
    if _slice.start == _slice.stop:
       ^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'start'

Newton Migration Guide

Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.

  • The migration guide in docs/migration.rst is up-to date

Before your PR is "Ready for review"

  • Necessary tests have been added and new examples are tested (see newton/tests/test_examples.py)
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an error when using an integer index in attribute selection within views. Integer indices are now handled as single-position slices, preventing occasional AttributeErrors.
    • Ensures consistent behavior across integer, frequency-based, and slice-based selections for more reliable indexing.
    • No changes to public APIs.

Signed-off-by: Lukasz Wawrzyniak <lwawrzyniak@nvidia.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 18, 2025

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@coderabbitai

coderabbitai Bot commented Sep 18, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated ArticulationView._get_attribute_array in newton/_src/utils/selection.py to normalize integer _slice inputs into a one-element Python slice. Existing handling for None (frequency-based) and Slice inputs is unchanged. Non-int, non-slice inputs continue to raise TypeError. No public API signatures were modified.

Changes

Cohort / File(s) Summary
Selection slicing handling
newton/_src/utils/selection.py
Normalize int _slice to slice(i, i+1) inside ArticulationView._get_attribute_array; retain existing None and slice paths; maintain TypeError for unsupported types; avoids AttributeError from accessing .start/.stop on ints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • AntoineRichard

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change — fixing handling of a selection slice when an integer is provided — and directly matches the PR objective to prevent the AttributeError in ArticulationView._get_attribute_array, so it is concise, focused, and relevant to the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
newton/_src/utils/selection.py (1)

548-559: Align type hints with accepted _slice types.

_signatures accept int in practice; annotations still say slice. Update for accuracy and better static checking.

Apply this diff:

-    def _get_attribute_values(self, name: str, source: Model | State | Control, _slice: slice | None = None):
+    def _get_attribute_values(self, name: str, source: Model | State | Control, _slice: Slice | int | None = None):
@@
-        self, name: str, target: Model | State | Control, values, mask=None, _slice: slice | None = None
+        self, name: str, target: Model | State | Control, values, mask=None, _slice: Slice | int | None = None
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb9737 and f4f4ffe.

📒 Files selected for processing (1)
  • newton/_src/utils/selection.py (1 hunks)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
  • GitHub Check: Run GPU Benchmarks (Pull Request)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)

Comment thread newton/_src/utils/selection.py
@nvlukasz nvlukasz enabled auto-merge (squash) September 18, 2025 16:58
@nvlukasz nvlukasz merged commit a49b4fc into newton-physics:main Sep 18, 2025
12 checks passed
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
Signed-off-by: Lukasz Wawrzyniak <lwawrzyniak@nvidia.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
Signed-off-by: Lukasz Wawrzyniak <lwawrzyniak@nvidia.com>
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.

2 participants