Skip recursive map_object for scalars with no range#173
Merged
amc-corey-cox merged 2 commits intomainfrom Mar 30, 2026
Merged
Conversation
When a slot has `range=None` and no `any_of` enums, `_map_value_by_range` now returns scalar values directly instead of recursing into `map_object` with `None` as the source type. This eliminates spurious "Unexpected: ... for type None" warnings.
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts ObjectTransformer._map_value_by_range to avoid pointless recursion when the source slot has no declared range, reducing noisy “Unexpected …” warnings during normal transforms (Fixes #172).
Changes:
- Add a fast-path return for scalar values when
source_class_slot.rangeisNone/"Any"and there are noany_ofenums. - Prevents
map_object(..., source_type=None, ...)being called for scalar values in that case.
Comments suppressed due to low confidence (1)
src/linkml_map/transformer/object_transformer.py:606
- The new early-return only skips recursion when
vitself is a scalar. For multivalued slots withrangeNone/"Any" (e.g.,vis a list of strings/ints), this still recurses intomap_objectfor each element and will continue emitting the same spurious "Unexpected" warnings. Consider extending the guard to also return the collection unchanged whenvis a list/dict whose elements/values are all scalars (i.e., nothing nested to recurse into).
# No range and no any_of enums: nothing to recurse into for scalars
if not isinstance(v, (dict, list)):
return v
if source_class_slot.multivalued:
if isinstance(v, list):
return [self.map_object(v1, source_class_slot_range, target_range) for v1 in v]
elif isinstance(v, dict):
Contributor
Author
|
@amc-corey-cox this works for me but I am not 100% certain of the side effects. As far as I can see, the only consequence is avoiding an unnecessary warning to be printed. |
Extend the no-range scalar short-circuit to also handle lists of scalars. Without this, multivalued scalar slots with no explicit range fall through to map_object, which logs spurious "Unexpected" warnings for each element. Add regression tests asserting both scalar and multivalued scalar slots with no range produce correct output without warnings.
amc-corey-cox
approved these changes
Mar 30, 2026
Contributor
amc-corey-cox
left a comment
There was a problem hiding this comment.
This looks good to me. Nice work! Thanks @matentzn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #172
When a slot has
range=Noneand noany_ofenums,_map_value_by_rangenow returns scalar values directly instead of recursing intomap_objectwithNoneas the source type. This eliminates spurious "Unexpected: ... for type None" warnings.