Skip to content
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

Enrico/bug context #1944

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Pint Changelog
0.25 (unreleased)
-----------------

- Fixed bug when using context and added regression test.
- Fix the default behaviour for pint-convert (cli) for importing uncertainties package (PR #2032, Issue #2016)
- Added mu and mc as alternatives for SI micro prefix
- Added ℓ as alternative for liter
Expand All @@ -15,6 +16,7 @@ Pint Changelog
0.24.1 (2024-06-24)
-----------------

- Fixed bug when using context and added regression test. (This PR)
- Fix custom formatter needing the registry object. (PR #2011)
- Support python 3.9 following difficulties installing with NumPy 2. (PR #2019)
- Fix default formatting of dimensionless unit issue. (PR #2012)
Expand Down
1 change: 1 addition & 0 deletions pint/facets/context/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def enable_contexts(

# Finally we add them to the active context.
self._active_ctx.insert_contexts(*contexts)
self._build_cache()
self._switch_context_cache_and_units()

def disable_contexts(self, n: int | None = None) -> None:
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions pint/testsuite/regressions/conv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Density
density_lng = 2.244 * cubic_metre_lng / metric_ton

# Calorific value
cv_lng = 1.22 * toe / metric_ton * 1.054261895

metric_tons_per_second = metric_ton / s

@context lng
[volume] / [time] -> [mass] / [time]: value / density_lng
[mass] / [time] -> [volume] / [time]: value * density_lng
[mass] / [time] -> [energy] / [time]: value * cv_lng
[energy] / [time] -> [mass] / [time]: value / cv_lng
@end
10 changes: 10 additions & 0 deletions pint/testsuite/regressions/test_contexts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pint import UnitRegistry


class TestRegressions:
def test_lng_conversion(self):
ureg = UnitRegistry()
ureg.load_definitions("pint/testsuite/regressions/conv.txt")
ureg.enable_contexts("lng")
u = ureg.Unit("watt")
assert u.compatible_units()
Loading