Skip to content

add kwargs in array and functional file #8508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2025

Conversation

IamTingTing
Copy link
Contributor

@IamTingTing IamTingTing commented Jul 7, 2025

Fixes #8492

Description

This PR adds support for **kwargs in the ResizeWithPadOrCrop transform to fix the issue where extra keyword arguments were ignored, causing errors in some workflows.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Summary by CodeRabbit

  • New Features

    • Enhanced zoom functionality to support additional parameters, allowing for greater flexibility in image transformation operations.
  • Refactor

    • Improved handling of optional arguments in zoom-related transformations for more customizable behavior.

Copy link

coderabbitai bot commented Jul 7, 2025

"""

Walkthrough

The changes update the Zoom transform and its underlying zoom function to ensure that any additional keyword arguments (**kwargs) are correctly forwarded through all layers, including padding and cropping operations. No other logic or control flow is modified.

Changes

File(s) Change Summary
monai/transforms/spatial/array.py Forwarded **self.kwargs to the zoom function in the Zoom class's __call__ method.
monai/transforms/spatial/functional.py Updated zoom function signature to accept **kwargs and forwarded them to padding/cropping.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZoomTransform
    participant ZoomFunction
    participant PadOrCrop

    User->>ZoomTransform: __call__(img, ...)
    ZoomTransform->>ZoomFunction: zoom(img, ..., **kwargs)
    ZoomFunction->>PadOrCrop: ResizeWithPadOrCrop(..., **kwargs)
    PadOrCrop-->>ZoomFunction: padded/cropped image
    ZoomFunction-->>ZoomTransform: zoomed image
    ZoomTransform-->>User: result
Loading

Assessment against linked issues

Objective Addressed Explanation
Forward kwargs from RandZoom/Zoom to the underlying zoom method (#8492)
Ensure kwargs are passed for fill values or padding in pad/crop (#8492)

Poem

A hop and a skip, through the code we zoom,
Passing kwargs along, to banish old gloom.
Padding and cropping, now flexible too,
Transforming with care, as rabbits would do.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a915108 and 943f225.

📒 Files selected for processing (2)
  • monai/transforms/spatial/array.py (1 hunks)
  • monai/transforms/spatial/functional.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • monai/transforms/spatial/array.py
  • monai/transforms/spatial/functional.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: min-dep-pytorch (2.5.1)
  • GitHub Check: min-dep-os (macOS-latest)
  • GitHub Check: min-dep-pytorch (2.6.0)
  • GitHub Check: min-dep-pytorch (2.4.1)
  • GitHub Check: min-dep-os (windows-latest)
  • GitHub Check: min-dep-os (ubuntu-latest)
  • GitHub Check: min-dep-py3 (3.12)
  • GitHub Check: min-dep-py3 (3.9)
  • GitHub Check: min-dep-py3 (3.10)
  • GitHub Check: min-dep-py3 (3.11)
  • GitHub Check: quick-py3 (macOS-latest)
  • GitHub Check: flake8-py3 (pytype)
  • GitHub Check: build-docs
  • GitHub Check: quick-py3 (windows-latest)
  • GitHub Check: quick-py3 (ubuntu-latest)
  • GitHub Check: flake8-py3 (mypy)
  • GitHub Check: packaging
  • GitHub Check: flake8-py3 (codeformat)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🧹 Nitpick comments (1)
monai/transforms/spatial/functional.py (1)

414-414: Consider updating the docstring to document the **kwargs parameter.

The function signature now accepts **kwargs which are forwarded to ResizeWithPadOrCrop. Consider adding documentation for this parameter to clarify what additional arguments are supported (e.g., padding-related arguments like pad_kwargs).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d388d1c and a915108.

📒 Files selected for processing (2)
  • monai/transforms/spatial/array.py (1 hunks)
  • monai/transforms/spatial/functional.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
monai/transforms/spatial/functional.py (1)
monai/transforms/croppad/array.py (1)
  • ResizeWithPadOrCrop (1397-1502)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: quick-py3 (ubuntu-latest)
  • GitHub Check: quick-py3 (windows-latest)
  • GitHub Check: quick-py3 (macOS-latest)
  • GitHub Check: packaging
  • GitHub Check: flake8-py3 (mypy)
  • GitHub Check: flake8-py3 (pytype)
  • GitHub Check: flake8-py3 (codeformat)
  • GitHub Check: build-docs
  • GitHub Check: min-dep-py3 (3.9)
  • GitHub Check: min-dep-pytorch (2.6.0)
  • GitHub Check: min-dep-os (windows-latest)
  • GitHub Check: min-dep-os (macOS-latest)
  • GitHub Check: min-dep-py3 (3.11)
  • GitHub Check: min-dep-py3 (3.12)
  • GitHub Check: min-dep-pytorch (2.4.1)
  • GitHub Check: min-dep-py3 (3.10)
  • GitHub Check: min-dep-pytorch (2.5.1)
  • GitHub Check: min-dep-os (ubuntu-latest)
🔇 Additional comments (3)
monai/transforms/spatial/array.py (1)

1111-1111: LGTM! Clean implementation of kwargs forwarding.

This change correctly implements the forwarding of additional keyword arguments from the Zoom transform constructor to the underlying zoom function. The implementation:

  • Properly forwards **self.kwargs to enable passing extra parameters to ResizeWithPadOrCrop operations
  • Is already documented in the constructor docstring (line 1036-1037)
  • Follows the established pattern used by other transforms in the codebase
  • Resolves the issue mentioned in the PR objectives without introducing breaking changes

The placement as the final parameter in the function call is appropriate and maintains code readability.

monai/transforms/spatial/functional.py (2)

453-453: LGTM! Correctly forwards kwargs in lazy evaluation path.

The **kwargs are properly forwarded to the ResizeWithPadOrCrop constructor, which accepts additional padding-related arguments through its **pad_kwargs parameter.


489-489: LGTM! Correctly forwards kwargs in eager evaluation path.

The **kwargs are properly forwarded to the ResizeWithPadOrCrop constructor, maintaining consistency with the lazy evaluation branch. This ensures that additional padding-related arguments are supported in both execution modes.

Signed-off-by: IamTingTing <6121smile@gmail.com>
@IamTingTing IamTingTing force-pushed the fix-randzoom-kwargs branch from a915108 to 943f225 Compare July 8, 2025 18:32
@IamTingTing IamTingTing closed this Jul 8, 2025
@IamTingTing IamTingTing reopened this Jul 8, 2025
@KumoLiu
Copy link
Contributor

KumoLiu commented Jul 11, 2025

/build

@KumoLiu KumoLiu enabled auto-merge (squash) July 11, 2025 14:00
@KumoLiu KumoLiu merged commit e499362 into Project-MONAI:dev Jul 11, 2025
26 checks passed
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.

Kwargs Not Passed in RandZoom
2 participants