Replace unit handling with Pint OpenwaterHealth/openlifu-python#153#454
Open
samueljwu wants to merge 1 commit into
Open
Replace unit handling with Pint OpenwaterHealth/openlifu-python#153#454samueljwu wants to merge 1 commit into
samueljwu wants to merge 1 commit into
Conversation
Collaborator
|
This is wonderful and much needed, thank you! Adding @peterhollender to review. I can take it as well, @peterhollender let me know |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replaces custom unit conversion logic in openlifu.util.units with Pint while keeping the existing public helpers used throughout geometry, simulation, and planning code.
Changes:
- Adds Pint as a runtime dependency.
- Reimplements unit normalization, type detection, SI scaling, and conversion through
UnitRegistry. - Expands unit conversion/type tests for legacy units and new Pint-backed aliases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/openlifu/util/units.py |
Replaces manual unit handling with Pint-backed normalization, dimensionality checks, and conversions. |
tests/test_units.py |
Adds parametrized coverage for conversion factors, unit classification, and newly supported aliases. |
pyproject.toml |
Adds pint to project dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+159
to
163
| try: | ||
| scl = _quantity(from_unit).to(_normalize_unit(to_unit)).magnitude | ||
| except DimensionalityError as exc: | ||
| type0 = getunittype(from_unit) | ||
| type1 = getunittype(to_unit) |
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.
Summary
Replaces the unit handling logic in
openlifu.util.unitswith Pint implementation while preserving the legacy API and expected behavior for supported units.Fixes #153
Changes
pintas a project dependencyunits.pyto usepint.UnitRegistryfor deminsionality checks and conversion factorsAll existing tests pass
Pre-commit hooks pass