Skip to content

Commit

Permalink
Merge pull request #40 from znichollscr/fix-pint-ppm-regression
Browse files Browse the repository at this point in the history
Fix pint regression
  • Loading branch information
znicholls authored May 17, 2023
2 parents f3c7ab1 + 90f835b commit 583c723
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changelog
=========

- (`#40 <https://github.com/openscm/openscm-units/pull/40>`_) Fixed broken definition of ppm, caused by regression in Pint where `'ppm' was added to Pint <https://github.com/hgrecco/pint/pull/1661>`_

v0.5.1
------

Expand Down
13 changes: 9 additions & 4 deletions src/openscm_units/_unit_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
}


class ScmUnitRegistry(pint.UnitRegistry):
class ScmUnitRegistry(pint.UnitRegistry): # pylint: disable=too-many-ancestors
"""
Unit registry class.
Expand Down Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down

0 comments on commit 583c723

Please sign in to comment.