Skip to content

Conversation

@benk-mira
Copy link
Contributor

@benk-mira benk-mira commented Jan 13, 2026

GEOPY-2632 - Simplify the BaseForm.infer method

@github-actions github-actions bot changed the title Geopy 2632 GEOPY-2632: Simplify the BaseForm.infer method Jan 13, 2026
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 93.54839% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.13%. Comparing base (ef4d20c) to head (3cb64b3).

Files with missing lines Patch % Lines
geoh5py/shared/utils.py 91.11% 2 Missing and 2 partials ⚠️
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     
Files with missing lines Coverage Δ
geoh5py/ui_json/forms.py 95.91% <100.00%> (+1.13%) ⬆️
geoh5py/shared/utils.py 91.72% <91.11%> (-0.08%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@domfournier domfournier left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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.

Comment on lines +1380 to +1382
n_weak = np.array(
[len(weak_indicators[i].intersection(data)) for i, c in enumerate(children)]
)
Copy link
Contributor

@domfournier domfournier Jan 16, 2026

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])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this case?

raise ValueError(f"Could not match data: {data} to any of the children.")


def no_required_indicators(parent: T, children: list[T]) -> list[T]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused function

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.

3 participants