Skip to content

fix: adaptor map_names calls dict as function when inputs is a name-mapping dict#8907

Open
aymuos15 wants to merge 3 commits into
Project-MONAI:devfrom
aymuos15:fix/adaptors-map-names
Open

fix: adaptor map_names calls dict as function when inputs is a name-mapping dict#8907
aymuos15 wants to merge 3 commits into
Project-MONAI:devfrom
aymuos15:fix/adaptors-map-names

Conversation

@aymuos15

@aymuos15 aymuos15 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

fix: adaptor map_names calls dict as function when inputs is a name-mapping dict

When adaptor wraps a function with **kwargs and inputs is a dict, the map_names helper calls input_map(k, k) instead of input_map.get(k, k), raising TypeError before any data reaches the wrapped function. The fix uses input_map.get(k, k) so the dict is looked up rather than called, falling back to the original key when no mapping exists.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • 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.

aymuos15 added 2 commits June 8, 2026 20:51
When adaptor wraps a function with **kwargs and inputs is a dict
(name-mapping mode), map_names() called input_map(k, k) which
treats the dict as a callable, raising TypeError. Use .get(k, k)
to look up the mapping instead.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Tests that adaptor correctly renames keys when the wrapped function
has **kwargs and inputs is a name-mapping dict. Fails before the
fix with TypeError: 'dict' object is not callable.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Fixed the map_names helper in monai/transforms/adaptors.py to use dict-style get() fallback instead of callable invocation for key remapping. This enables proper input name mapping when adapting functions with **kwargs. Added test_kwargs_with_dict_inputs to verify the adaptor correctly handles dictionary-based input and output mappings with kwargs-accepting functions.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and specifically describes the bug fix: a dict being incorrectly called as a function in the map_names helper when inputs is a name-mapping dict.
Description check ✅ Passed Description explains the bug, fix, and impact clearly. Includes proper template sections with non-breaking change and new tests marked. Integration and quick test checkboxes appropriately left unchecked.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ 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.

🧹 Nitpick comments (1)
monai/transforms/adaptors.py (1)

142-143: 💤 Low value

Consider adding a docstring to the helper.

Per guidelines, all definitions should have docstrings describing parameters and return values, even for internal helpers.

📝 Suggested docstring
 def map_names(ditems, input_map):
+    """Remap dictionary keys using input_map, falling back to original keys.
+    
+    Args:
+        ditems: Dictionary to remap.
+        input_map: Mapping from original to target key names.
+    
+    Returns:
+        Dictionary with remapped keys.
+    """
     return {input_map.get(k, k): v for k, v in ditems.items()}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@monai/transforms/adaptors.py` around lines 142 - 143, Add a docstring to the
helper function map_names in monai/transforms/adaptors.py that concisely
describes the parameters and return value: document that ditems is a dict of
original key->value pairs, input_map is a mapping used to rename keys (with
input_map.get(k, k) behavior), and the function returns a new dict with keys
remapped; include parameter types and a brief example or note about fallback
behavior when a key is not found in input_map.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@monai/transforms/adaptors.py`:
- Around line 142-143: Add a docstring to the helper function map_names in
monai/transforms/adaptors.py that concisely describes the parameters and return
value: document that ditems is a dict of original key->value pairs, input_map is
a mapping used to rename keys (with input_map.get(k, k) behavior), and the
function returns a new dict with keys remapped; include parameter types and a
brief example or note about fallback behavior when a key is not found in
input_map.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 625f7500-e5cb-4a3e-834b-04757c2cfb8e

📥 Commits

Reviewing files that changed from the base of the PR and between eccefc5 and c17fe26.

📒 Files selected for processing (2)
  • monai/transforms/adaptors.py
  • tests/transforms/test_adaptors.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