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

Fix pint regression #40

Merged
merged 5 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 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()
znichollscr marked this conversation as resolved.
Show resolved Hide resolved

def enable_contexts(self, *names_or_contexts, **kwargs):
"""
Expand Down