Skip to content

Remove unused n_dims parameter from Fourier.inv_shift_fourier#8766

Open
aymuos15 wants to merge 2 commits intoProject-MONAI:devfrom
aymuos15:remove-unused-n_dims
Open

Remove unused n_dims parameter from Fourier.inv_shift_fourier#8766
aymuos15 wants to merge 2 commits intoProject-MONAI:devfrom
aymuos15:remove-unused-n_dims

Conversation

@aymuos15
Copy link
Contributor

@aymuos15 aymuos15 commented Mar 3, 2026

As discussed here: #8762

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

The inv_shift_fourier method in the Fourier class had its signature changed by removing the n_dims parameter. Its new signature is (k: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False) -> NdarrayOrTensor. Callers passing n_dims will need to stop doing so; behavior and return type otherwise unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning Description lacks required template sections: it's missing description text, types of changes checkboxes, and test/documentation updates. Only references a GitHub discussion without explaining the change. Add a description section explaining why the parameter was removed, check appropriate boxes for breaking changes and test status, and confirm any documentation updates.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main change: removing the unused n_dims parameter from the Fourier.inv_shift_fourier method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@monai/transforms/utils.py`:
- Around line 1887-1889: The public kwarg n_dims was removed from
inv_shift_fourier which will break callers using n_dims=; restore a deprecated
no-op parameter by adding n_dims: Optional[int] = None to the inv_shift_fourier
signature, emit a warnings.warn(..., DeprecationWarning) if n_dims is not None,
and ignore its value when computing (i.e., retain current behavior driven by
spatial_dims and as_contiguous). Update the function signature and add the
one-line deprecation warning near the top of inv_shift_fourier so downstream
code continues to work for one release cycle.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9ddd5e6 and 240e83a.

📒 Files selected for processing (1)
  • monai/transforms/utils.py

Comment on lines 1887 to 1889
def inv_shift_fourier(
k: NdarrayOrTensor, spatial_dims: int, n_dims: int | None = None, as_contiguous: bool = False
k: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False
) -> NdarrayOrTensor:
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add a deprecation bridge for the removed public n_dims argument.

Line 1888 removes a public kwarg; downstream calls using n_dims= will now fail with TypeError. Please keep a deprecated no-op arg for one release cycle (or gate this behind a clearly documented major-version break).

Proposed compatibility patch
 `@staticmethod`
 def inv_shift_fourier(
-    k: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False
+    k: NdarrayOrTensor,
+    spatial_dims: int,
+    n_dims: int | None = None,
+    as_contiguous: bool = False,
 ) -> NdarrayOrTensor:
@@
+    if n_dims is not None:
+        warnings.warn(
+            "`n_dims` is deprecated and ignored; use `spatial_dims` only.",
+            FutureWarning,
+            stacklevel=2,
+        )
     dims = tuple(range(-spatial_dims, 0))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def inv_shift_fourier(
k: NdarrayOrTensor, spatial_dims: int, n_dims: int | None = None, as_contiguous: bool = False
k: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False
) -> NdarrayOrTensor:
`@staticmethod`
def inv_shift_fourier(
k: NdarrayOrTensor,
spatial_dims: int,
n_dims: int | None = None,
as_contiguous: bool = False,
) -> NdarrayOrTensor:
if n_dims is not None:
warnings.warn(
"`n_dims` is deprecated and ignored; use `spatial_dims` only.",
FutureWarning,
stacklevel=2,
)
dims = tuple(range(-spatial_dims, 0))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@monai/transforms/utils.py` around lines 1887 - 1889, The public kwarg n_dims
was removed from inv_shift_fourier which will break callers using n_dims=;
restore a deprecated no-op parameter by adding n_dims: Optional[int] = None to
the inv_shift_fourier signature, emit a warnings.warn(..., DeprecationWarning)
if n_dims is not None, and ignore its value when computing (i.e., retain current
behavior driven by spatial_dims and as_contiguous). Update the function
signature and add the one-line deprecation warning near the top of
inv_shift_fourier so downstream code continues to work for one release cycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been unused for a very long time. I doubt anyone will crash because of this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for all calls to inv_shift_fourier in the codebase
echo "=== Searching for inv_shift_fourier usage ==="
rg -n -C3 'inv_shift_fourier' --type=py

echo ""
echo "=== Checking if n_dims parameter is ever passed ==="
rg -n 'inv_shift_fourier.*n_dims' --type=py

echo ""
echo "=== Searching in tests specifically ==="
fd -e py -p '*test*.py' --exec rg -l 'inv_shift_fourier' {}

Unrecoverable error: Failed to clone repository


@aymuos15, understood. If the parameter has been unused for that long, the breaking change risk is minimal. Your judgment on this makes sense given your familiarity with the codebase and the prior discussion in #8762.

@aymuos15 aymuos15 force-pushed the remove-unused-n_dims branch from 240e83a to 9303468 Compare March 3, 2026 19:38
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@aymuos15 aymuos15 force-pushed the remove-unused-n_dims branch from 18c38a2 to 25d47e4 Compare March 4, 2026 06:49
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
monai/transforms/utils.py (1)

1887-1906: ⚠️ Potential issue | 🟡 Minor

Add coverage for the signature change.

inv_shift_fourier is a modified public definition, but no related test update is shown here. Please add/update tests for the new call form and expected behavior when n_dims is passed.

As per coding guidelines, "Ensure new or modified definitions will be covered by existing or new unit tests."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@monai/transforms/utils.py` around lines 1887 - 1906, Update unit tests to
cover the modified public signature of inv_shift_fourier: add tests that call
monai.transforms.utils.inv_shift_fourier with the new keyword form n_dims (in
addition to existing spatial_dims calls) to ensure both produce identical
outputs; include cases for both torch.Tensor and numpy.ndarray inputs, assert
correct real-valued output after inverse shift+ifft, and verify
as_contiguous=True returns a contiguous array/tensor while False preserves
original contiguity. Target tests around the inv_shift_fourier function, using
small 1D/2D/3D k-space examples and compare results between calls using
spatial_dims=<n> and n_dims=<n> to validate the signature change is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@monai/transforms/utils.py`:
- Around line 1887-1906: Update unit tests to cover the modified public
signature of inv_shift_fourier: add tests that call
monai.transforms.utils.inv_shift_fourier with the new keyword form n_dims (in
addition to existing spatial_dims calls) to ensure both produce identical
outputs; include cases for both torch.Tensor and numpy.ndarray inputs, assert
correct real-valued output after inverse shift+ifft, and verify
as_contiguous=True returns a contiguous array/tensor while False preserves
original contiguity. Target tests around the inv_shift_fourier function, using
small 1D/2D/3D k-space examples and compare results between calls using
spatial_dims=<n> and n_dims=<n> to validate the signature change is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07cec335-235f-41e7-b958-fe216a1bd486

📥 Commits

Reviewing files that changed from the base of the PR and between 25d47e4 and 2089639.

📒 Files selected for processing (1)
  • monai/transforms/utils.py

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