Skip to content

Commit c82de9c

Browse files
committed
Updated to avoid Pint 0.18 bug
1 parent 0a806a5 commit c82de9c

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

gemd/units/impl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Implementation of units."""
22
import re
33

4-
from pint import UnitRegistry, Unit, register_unit_format, Quantity
4+
from pint import UnitRegistry, Unit, register_unit_format
55
from pint.compat import tokenizer
66
from tokenize import NAME, NUMBER, OP
77
# alias the error that is thrown when units are incompatible
@@ -118,10 +118,8 @@ def parse_units(units: Union[str, Unit, None]) -> Union[str, Unit, None]:
118118
elif units == '':
119119
return 'dimensionless'
120120
elif isinstance(units, str):
121-
parsed = _REGISTRY(units)
122-
if not isinstance(parsed, Quantity) or parsed.magnitude != 1:
123-
raise ValueError(f"Units cannot start with (or just be) numbers: {units}")
124-
return f"{parsed.u:clean}"
121+
parsed = _REGISTRY.parse_units(units)
122+
return f"{parsed:clean}"
125123
elif isinstance(units, Unit):
126124
return units
127125
else:

gemd/units/tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_parse_unexpected():
6060
"16.2" # No values that are just floats
6161
]
6262
for unit in scaling:
63-
with pytest.raises(ValueError):
63+
with pytest.raises(ValueError, match="scaling"):
6464
parse_units(unit)
6565

6666
definition = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
install_requires=[
2121
"toolz>=0.10.0,<1",
22-
"pint>=0.18,<0.21",
22+
"pint>=0.19,<0.21",
2323
"deprecation>=2.0.7,<3"
2424
],
2525
extras_require={

0 commit comments

Comments
 (0)