-
Notifications
You must be signed in to change notification settings - Fork 1.2k
added list extend to MultiSampleTrait #8531
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
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThe change modifies the Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes detected. Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (19)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
DCO Remediation Commit for Lukas Folle <[email protected]> I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: eeb7e12 Signed-off-by: Lukas Folle <[email protected]>
There was a problem hiding this 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
🧹 Nitpick comments (5)
monai/transforms/transform.py (5)
127-137
: Docstring: fix parameter name and clarify behavior“map_data” should be “map_items”, and mention that list/tuple returns are flattened one level.
- If `data` is a list or tuple and `map_data` is True, each item of `data` will be transformed + If `data` is a list or tuple and `map_items` is True, each item of `data` will be transformed and this method returns a list of outcomes. @@ - - If an integer is provided, it specifies the maximum level of nesting to which the transformation - should be recursively applied. This allows treating multi-sample transforms applied after another - multi-sample transform while controlling how deep the mapping goes. + - If an integer is provided, it specifies the maximum level of nesting to which the transformation + should be recursively applied. When a transform returns a list or tuple, the results are flattened + one level at each mapped depth.
174-199
: Exception logging: style-only — OK; avoid mutatingdata
for loggingFormatting is good. Minor nit: don’t reassign
data
when logging a first element; use a temp to avoid shadowing.- if isinstance(data, (list, tuple)): - data = data[0] + if isinstance(data, (list, tuple)): + _data_for_log = data[0] + else: + _data_for_log = data @@ - if isinstance(data, dict): - for k, v in data.items(): + if isinstance(_data_for_log, dict): + for k, v in _data_for_log.items(): _log_stats(data=v, prefix=k) else: - _log_stats(data=data) + _log_stats(data=_data_for_log)
459-461
: TypeError message should report offending element type, notkeys
Inside the loop, report
type(key).__name__}
for clarity.- raise TypeError( - f"keys must be one of (Hashable, Iterable[Hashable]) but is {type(keys).__name__}." - ) + raise TypeError( + f"keys must be one of (Hashable, Iterable[Hashable]); " + f"found element of type {type(key).__name__}." + )
515-518
: key_iterator: signature formatting — OKOptional: annotate as Generator[Any, None, None] for completeness.
66-68
: Docstring nits in _apply_transform
- Typo: “this class is function” → “this function”.
- Sphinx ref missing closing backtick: :ref:
Lazy Resampling topic<lazy_resampling>
.Also applies to: 75-78
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (1)
monai/transforms/transform.py
(10 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
⚙️ CodeRabbit Configuration File
Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.
Files:
monai/transforms/transform.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). (19)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: flake8-py3 (codeformat)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: flake8-py3 (pytype)
- GitHub Check: build-docs
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: flake8-py3 (mypy)
- GitHub Check: packaging
- GitHub Check: min-dep-os (ubuntu-latest)
- GitHub Check: min-dep-os (macOS-latest)
- GitHub Check: min-dep-pytorch (2.7.1)
- GitHub Check: min-dep-pytorch (2.4.1)
- GitHub Check: min-dep-os (windows-latest)
- GitHub Check: min-dep-py3 (3.10)
- GitHub Check: min-dep-pytorch (2.6.0)
- GitHub Check: min-dep-pytorch (2.5.1)
- GitHub Check: min-dep-py3 (3.9)
- GitHub Check: min-dep-py3 (3.11)
- GitHub Check: min-dep-py3 (3.12)
🔇 Additional comments (8)
monai/transforms/transform.py (8)
93-108
: _apply_transform: style-only refactor — OKMultiline call/returns improve readability; logic unchanged.
225-263
: set_random_state: seeding cast and MAX_SEED mod — OKCasting to int64 and modding by MAX_SEED is appropriate for NumPy 2.0 compatibility; type checks/readability improved.
256-259
: Type check message — OKClear, explicit message; no change requested.
277-279
: NotImplemented message — OKConsistent and informative.
335-337
: NotImplemented message — OKConsistent and informative.
441-448
: Hook attachment formatting — OKNo behavioral change; readability improved.
481-483
: sync_meta_info call — OKStyle change only; behavior preserved.
511-513
: NotImplemented message — OKConsistent across classes.
I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
There was a problem hiding this 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
🧹 Nitpick comments (2)
monai/transforms/transform.py (2)
156-165
: Type annotation tighteningThe function currently declares
-> list[Any] | ReturnType
but constructslist[ReturnType]
. Prefer narrowing tolist[ReturnType] | ReturnType
for consistency.Proposed signature (outside this hunk):
def apply_transform(...) -> list[ReturnType] | ReturnType: ...
515-518
: Return type hint could be more explicitkey_iterator yields either a Hashable or a tuple when extra iterables are present. Consider tightening the annotation for better tooling.
- ) -> Generator: + ) -> Generator[Hashable | tuple[Hashable, ...], None, None]:
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (1)
monai/transforms/transform.py
(10 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
⚙️ CodeRabbit Configuration File
Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.
Files:
monai/transforms/transform.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). (4)
- GitHub Check: quick-py3 (ubuntu-latest)
- GitHub Check: quick-py3 (windows-latest)
- GitHub Check: quick-py3 (macOS-latest)
- GitHub Check: packaging
🔇 Additional comments (14)
monai/transforms/transform.py (14)
93-96
: Refactor-only: OKCall-site reformatting reads cleaner. No functional change.
98-103
: Refactor-only: OKTuple-unpack branch formatting is fine. No logic change.
104-108
: Refactor-only: OKSingle-arg branch formatting is fine. No logic change.
174-199
: Refactor-only: OKError-logging reformatting is clear; logic unchanged.
225-227
: Refactor-only: OKSignature reflow is fine; types unchanged.
245-251
: Seed normalization: OKModulo against MAX_SEED post np.int64 cast is reasonable for NumPy 2.0 compat.
256-258
: Refactor-only: OKTypeError message formatting is fine.
277-279
: Refactor-only: OKNotImplementedError reflow is fine.
335-337
: Refactor-only: OKAbstract call error message reflow is fine.
441-443
: Refactor-only: OKHook attachment formatting is clearer.
447-448
: Refactor-only: OKInverse hook formatting is clearer.
459-461
: Refactor-only: OKType check error formatting is fine.
481-483
: Refactor-only: OKsync_meta_info call formatting is fine.
511-513
: Refactor-only: OKNotImplementedError reflow is fine.
DCO Remediation Commit for Lukas Folle <[email protected]> I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
DCO Remediation Commit for Lukas Folle <[email protected]> I, Lukas Folle <[email protected]>, hereby add my Signed-off-by to this commit: e0cda55 Signed-off-by: Lukas Folle <[email protected]>
All remaining failing CI runs are not coming from this change. |
# Only extend if we're at the leaf level (map_items_ == 1) and the transform | ||
# actually returned a list (not preserving nested structure) | ||
if isinstance(res_item, list) and map_items_ == 1: | ||
if not isinstance(item, (list, tuple)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within the containing block res_item
will always be a list (line 151) and so this if statement's condition is always false. I'm not sure the logic is what you're expecting it to be here?
Hi @lukas-folle-snkeos thanks for the contribution! Please check the logic I flagged and we do need tests to check that this behaviour is correct. You can take the mentioned issue as an example of what to check for but I think we need to test this logic thoroughly and more clearly document what's going on in comments. |
Fixes #8528.
Description
A few sentences describing the changes proposed in this pull request.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.