Skip to content

test(nifti): cover 2D writer without target affine - #9173

Open
px12811 wants to merge 2 commits into
Project-MONAI:devfrom
px12811:9166-nibabel-writer-2d
Open

px12811 wants to merge 2 commits into
Project-MONAI:devfrom
px12811:9166-nibabel-writer-2d

Conversation

@px12811

@px12811 px12811 commented Oct 14, 2026

Copy link
Copy Markdown

Summary

Add a regression test for the public NibabelWriter path reported in #9166.

The reported TypeError is already resolved on dev by the general spatial_resample fix in #9080. This PR adds direct coverage for the original writer-level scenario so the regression cannot return without failing this test.

The new test writes a 2D channel-less array with spatial_ndim=None, original_affine=None, and no spatial_shape, then verifies the saved data and affine.

Validation

  • On e28a2c07^, the new test fails with the reported TypeError: '>=' not supported between instances of 'NoneType' and 'int'.
  • On current dev, the new test passes.
  • python -m pytest tests/data/test_nifti_rw.py -q: 42 passed
  • python -m pytest tests/transforms/test_spatial_resample.py -q: 76 passed
  • python -m pytest tests/data/test_image_rw.py -q: 2 passed, 28 skipped in the local minimal environment
  • ruff, black --check, isort --check-only, and git diff --check: passed

AI disclosure

This contribution was prepared with Codex assistance and reviewed by the submitter, who will respond to review comments personally.

Add a regression test for the NibabelWriter path reported in Project-MONAI#9166. The underlying fix landed in Project-MONAI#9080, but the writer-level behavior was not covered directly.

Assisted-by: Codex <noreply@openai.com>
Signed-off-by: peng xiang <78131130+px12811@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Project-MONAI/MONAI/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5576499a-6161-4744-8255-6dc3e340d4dc
📥 Commits

Reviewing files that changed from the base of the PR and between 87133d8 and 4de9bb1.

📒 Files selected for processing: 1
  • tests/data/test_nifti_rw.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Adds a test that writes channel-less 2D data with spatial_ndim=None and no original_affine. The test checks that saved values remain unchanged and that the saved affine is the identity matrix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 4de9b

This change adds regression coverage for 2D NIfTI writing without an original affine. No actionable merge-blocking risk is evident; it appears ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the added NIfTI regression test for the 2D writer case without a target affine.
Description check Passed The description explains the regression scenario, test coverage, prior fix, validation results, and AI disclosure. It does not use the repository template headings or checkbox section, but it provides…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the regression scenario, test coverage, prior fix, validation results, and AI disclosure. It does not use the repository template headings or checkbox section, but it provides the required technical context and is mostly complete.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@px12811

px12811 commented Oct 17, 2026

Copy link
Copy Markdown
Author

Merged dev to clear the "behind" state.

Local: the touched file, tests/data/test_nifti_rw.py, -> 42 passed (including test_write_2d).

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.

1 participant