diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 81a989c..ccf4b10 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,8 @@ Changelog ========= +- (`#40 `_) Fixed broken definition of ppm, caused by regression in Pint where `'ppm' was added to Pint `_ + v0.5.1 ------ diff --git a/src/openscm_units/_unit_registry.py b/src/openscm_units/_unit_registry.py index 0f504f9..3d66c01 100644 --- a/src/openscm_units/_unit_registry.py +++ b/src/openscm_units/_unit_registry.py @@ -302,7 +302,7 @@ } -class ScmUnitRegistry(pint.UnitRegistry): +class ScmUnitRegistry(pint.UnitRegistry): # pylint: disable=too-many-ancestors """ Unit registry class. @@ -332,6 +332,8 @@ def __init__(self, *args, metric_conversions=None, **kwargs): Passed to the ``__init__`` method of the super class """ self._metric_conversions = metric_conversions + # If we didn't call init here, we wouldn't need to rebuild the cache + # below but that also feels like a bad pattern super().__init__(*args, **kwargs) def add_standards(self): @@ -354,9 +356,12 @@ def add_standards(self): "Tt = 1000000000000 * t" ) # since Tt is used for "tex" in the defaults - self.define("ppt = [concentrations]") - self.define("ppb = 1000 * ppt") - self.define("ppm = 1000 * ppb") + self.define("ppm = [concentrations]") + self.define("ppb = ppm / 1000") + self.define("ppt = ppb / 1000") + # Have to rebuild cache to get right units for ppm as it is defined in + # pint + self._build_cache() def enable_contexts(self, *names_or_contexts, **kwargs): """