-
Notifications
You must be signed in to change notification settings - Fork 12
GEOPY-2632: Simplify the BaseForm.infer method #829
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: develop
Are you sure you want to change the base?
Conversation
# Conflicts: # geoh5py/shared/utils.py
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #829 +/- ##
===========================================
- Coverage 91.15% 91.13% -0.03%
===========================================
Files 113 113
Lines 9999 10009 +10
Branches 1883 1875 -8
===========================================
+ Hits 9115 9122 +7
- Misses 468 474 +6
+ Partials 416 413 -3
🚀 New features to boost your workflow:
|
Co-authored-by: domfournier <dominiquef@mirageoscience.com>
…n check in favor of double return statements.
domfournier
left a comment
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.
The logic is pretty complicated - I have flashbacks from InputFile.
Can you comment the lines for the different cases?
| raise ValueError(f"Could not infer form from data: {data}") | ||
|
|
||
| form = {to_snake(k): v for k, v in form.items()} | ||
| children = all_subclasses(cls) |
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 doesn't have to happen here, everytime we infer a form. It could technically be stashed on import
| def best_match_subclass(parent: T, children: list[T], data: dict[str, Any]) -> T: | ||
| """Choose the subclass with the best matching attributes""" | ||
|
|
||
| strong_indicators, weak_indicators = indicator_attributes(parent, children) |
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.
Same with this line - could be a constant on import.
| n_weak = np.array( | ||
| [len(weak_indicators[i].intersection(data)) for i, c in enumerate(children)] | ||
| ) |
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.
Why do we care for the "weak" non-required?
| if len(candidates) == 1: | ||
| return candidates | ||
| if len(candidates) > 1 and len(candidates) < len(children): | ||
| return candidates[np.argmin([len(k.model_fields) for k in candidates])] |
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.
What's this case?
geoh5py/shared/utils.py
Outdated
| raise ValueError(f"Could not match data: {data} to any of the children.") | ||
|
|
||
|
|
||
| def no_required_indicators(parent: T, children: list[T]) -> list[T]: |
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.
Unused function
GEOPY-2632 - Simplify the BaseForm.infer method