From 9b667cea62c96ba5e824714e5d194b4ab842b646 Mon Sep 17 00:00:00 2001 From: Chris Muthig Date: Wed, 19 Apr 2023 13:27:11 -0700 Subject: [PATCH 1/2] Create failing test --- pint/testsuite/test_diskcache.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pint/testsuite/test_diskcache.py b/pint/testsuite/test_diskcache.py index 399f9f765..ed5557a52 100644 --- a/pint/testsuite/test_diskcache.py +++ b/pint/testsuite/test_diskcache.py @@ -95,3 +95,13 @@ def test_change_file(tmp_path): assert ureg.x == 1235 files = tuple(ureg._diskcache.cache_folder.glob("*.pickle")) assert len(files) == 4 + + +def test_dimensional_equivalent_are_cached(tmp_path): + ureg = pint.UnitRegistry(cache_folder=tmp_path) + t = ureg.get_compatible_units("L") + assert len(t) > 0 + + ureg = pint.UnitRegistry(cache_folder=tmp_path) + t = ureg.get_compatible_units("L") + assert len(t) > 0 From a2ed394199940947985c0085944e156a8844bd1f Mon Sep 17 00:00:00 2001 From: Chris Muthig Date: Wed, 19 Apr 2023 13:27:50 -0700 Subject: [PATCH 2/2] Set cache from read cache files When building a unit registry using a cache, the read cache data is not getting leveraged. Instead a new cache is getting built, but without the dimensional equivalents. This creates a behavior where you create a new UnitRegistry from already cached files and call `get_compatible_units` it will always fail with a key error. --- pint/facets/plain/registry.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pint/facets/plain/registry.py b/pint/facets/plain/registry.py index ffa6fb43e..47640ced3 100644 --- a/pint/facets/plain/registry.py +++ b/pint/facets/plain/registry.py @@ -534,7 +534,9 @@ def _build_cache(self, loaded_files=None) -> None: if cache is None: self._build_cache() diskcache.save(self._cache, loaded_files, "build_cache") - return + else: + self._cache = cache + return self._cache = RegistryCache()