Skip to content

Commit f2bb344

Browse files
committed
Restore Pint 0.18 support
1 parent c82de9c commit f2bb344

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55
- '3.8'
66
- '3.9'
77
- '3.10'
8+
- '3.11'
89
env:
910
- PINT_VERSION=0.18
1011
- PINT_VERSION=0.20

gemd/units/impl.py

Lines changed: 6 additions & 3 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
4+
from pint import UnitRegistry, Unit, register_unit_format, Quantity
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,8 +118,11 @@ 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.parse_units(units)
122-
return f"{parsed:clean}"
121+
# TODO: parse_units has a bug resolved in 0.19, but 3.7 only supports up to 0.18
122+
parsed = _REGISTRY(units)
123+
if not isinstance(parsed, Quantity) or parsed.magnitude != 1:
124+
raise ValueError(f"Unit expression cannot have a leading scaling factor. {units}")
125+
return f"{parsed.u:clean}"
123126
elif isinstance(units, Unit):
124127
return units
125128
else:

setup.py

Lines changed: 2 additions & 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.19,<0.21",
22+
"pint>=0.18,<0.21",
2323
"deprecation>=2.0.7,<3"
2424
],
2525
extras_require={
@@ -39,5 +39,6 @@
3939
'Programming Language :: Python :: 3.8',
4040
'Programming Language :: Python :: 3.9',
4141
'Programming Language :: Python :: 3.10',
42+
'Programming Language :: Python :: 3.11',
4243
],
4344
)

0 commit comments

Comments
 (0)