-
Notifications
You must be signed in to change notification settings - Fork 8
Fix TypeError thrown when specifying interpolator for ANTsRegistrator #178
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: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -169,15 +169,16 @@ def transform( | |||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| start_time = datetime.datetime.now() | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # TODO - self.transformation_params | ||||||||||||||||||||||||||||||||||
| # we update the transformation parameters with the provided kwargs | ||||||||||||||||||||||||||||||||||
| transform_kwargs = {**self.transformation_params, **kwargs} | ||||||||||||||||||||||||||||||||||
| interpolator = transform_kwargs.pop('interpolator', interpolator) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| interpolator = transform_kwargs.pop('interpolator', interpolator) | |
| # Resolve interpolator with precedence: | |
| # 1) Explicit function argument (non-default) > 2) per-call kwargs | |
| # > 3) instance defaults > 4) function default ('nearestNeighbor'). | |
| # | |
| # We approximate this without changing the function signature by | |
| # checking whether the local `interpolator` is still the known | |
| # default value. Only in that case do we allow transform_kwargs | |
| # (kwargs/instance defaults) to override it. | |
| if interpolator == "nearestNeighbor": | |
| interpolator = transform_kwargs.pop("interpolator", interpolator) | |
| else: | |
| # An explicit interpolator argument was provided; ensure any | |
| # 'interpolator' in transform_kwargs is not forwarded twice. | |
| transform_kwargs.pop("interpolator", None) |
Copilot
AI
Mar 25, 2026
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.
This change fixes the duplicate interpolator keyword, but there’s no regression test ensuring that (a) providing transformation_params={'interpolator': ...} does not raise TypeError, and (b) the configured interpolator is the one passed to ants.apply_transforms. Adding a unit test that mocks ants.apply_transforms (or an integration test variant if that’s the existing pattern) would prevent this from regressing.
Copilot
AI
Mar 25, 2026
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.
Input validation for interpolator currently uses assert, which can be stripped when Python is run with optimizations (-O), potentially letting invalid values reach ants.apply_transforms and fail less clearly. Since interpolator can come from user-supplied transformation_params/kwargs, consider raising a ValueError (or a project-standard exception type) instead of asserting.
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.
@copilot apply changes based on this feedback
Copilot
AI
Apr 26, 2026
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.
interpolator is validated via assert. Assertions can be stripped with Python optimizations (-O), allowing invalid user-supplied interpolators (from transformation_params/kwargs) to reach ants.apply_transforms and fail less clearly. Prefer raising a runtime exception (e.g., ValueError) for this validation so it is always enforced (and update the docstring Raises: accordingly if you change the exception type).
Uh oh!
There was an error while loading. Please reload this page.