diff options
author | Hernan Grecco <hgrecco@gmail.com> | 2023-04-26 23:20:47 -0300 |
---|---|---|
committer | Hernan Grecco <hgrecco@gmail.com> | 2023-04-26 23:20:47 -0300 |
commit | 8b18388d1b1407d2813aa85e4a98ee15758cd7fa (patch) | |
tree | 9d2b80a058ebdc0a04cf6c4640b8e7bda6297e29 /pint | |
parent | c208b0edb87b244c4c40d4beba7be8ec32e57eaf (diff) | |
download | pint-8b18388d1b1407d2813aa85e4a98ee15758cd7fa.tar.gz |
Fix get_compatible_units for dynamically add units/dimensions
Close #1725
Diffstat (limited to 'pint')
-rw-r--r-- | pint/facets/plain/registry.py | 2 | ||||
-rw-r--r-- | pint/testsuite/test_issues.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index 94cc5ff..b7ca362 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -854,7 +854,7 @@ class PlainRegistry(metaclass=RegistryMeta): return frozenset() src_dim = self._get_dimensionality(input_units) - return self._cache.dimensional_equivalents[src_dim] + return self._cache.dimensional_equivalents.setdefault(src_dim, set()) # TODO: remove context from here def is_compatible_with( diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py index 8f16f81..6dd8f85 100644 --- a/pint/testsuite/test_issues.py +++ b/pint/testsuite/test_issues.py @@ -1073,3 +1073,8 @@ def test_issue1631(): q = 2 * ureg.meter assert isinstance(q, ureg.Quantity) assert isinstance(q, pint.Quantity) + + +def test_issue1725(registry_empty): + registry_empty.define("dollar = [currency]") + assert registry_empty.get_compatible_units("dollar") == set() |