Skip to content

Commit f3cd227

Browse files
authored
Update compatibility to include latest Pint (#222)
1 parent bb12bd1 commit f3cd227

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

gemd/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.1.8"
1+
__version__ = "2.1.9"

gemd/units/citrine_en.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Citrine customized units input file for Pint, based explicitly on the Pint defaults as
2-
# included release 0.23 (https://github.com/hgrecco/pint/releases/tag/0.23). The Pint Authors hold
3-
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.23/AUTHORS.
2+
# included release 0.24.3 (https://github.com/hgrecco/pint/releases/tag/0.24.3). The Pint Authors hold
3+
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.24.3/AUTHORS.
44
#
55
# The original copyright statement for the constants file reads:
66
#
@@ -116,7 +116,7 @@ pico- = 1e-12 = p-
116116
nano- = 1e-9 = n-
117117
# The micro (U+00B5) and Greek mu (U+03BC) are both valid prefixes,
118118
# and they often use the same glyph.
119-
micro- = 1e-6 = µ- = μ- = u-
119+
micro- = 1e-6 = µ- = μ- = u- = mu- = mc-
120120
milli- = 1e-3 = m-
121121
centi- = 1e-2 = c-
122122
deci- = 1e-1 = d-
@@ -269,7 +269,7 @@ hectare = 100 * are = ha = Hectare
269269

270270
# Volume
271271
[volume] = [length] ** 3
272-
liter = decimeter ** 3 = l = L = litre = Liter = Litre
272+
liter = decimeter ** 3 = l = L = ℓ = litre = Liter = Litre
273273
cubic_centimeter = centimeter ** 3 = cc = Cubic_Centimeter
274274
lambda = microliter = λ = Lambda
275275
stere = meter ** 3 = _ = Stere
@@ -543,12 +543,17 @@ buckingham = debye * angstrom = Buckingham
543543
bohr_magneton = e * hbar / (2 * m_e) = µ_B = mu_B
544544
nuclear_magneton = e * hbar / (2 * m_p) = µ_N = mu_N
545545

546+
# Refractive index
547+
[refractive_index] = []
548+
refractive_index_unit = [] = RIU
549+
546550
# Logaritmic Unit Definition
547551
# Unit = scale; logbase; logfactor
548552
# x_dB = [logfactor] * log( x_lin / [scale] ) / log( [logbase] )
549553

550554
# Logaritmic Units of dimensionless quantity: [ https://en.wikipedia.org/wiki/Level_(logarithmic_quantity) ]
551555

556+
decibelwatt = watt; logbase: 10; logfactor: 10 = dBW
552557
decibelmilliwatt = 1e-3 watt; logbase: 10; logfactor: 10 = dBm
553558
decibelmicrowatt = 1e-6 watt; logbase: 10; logfactor: 10 = dBu
554559

gemd/units/impl.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,24 @@ def _format_clean(unit, registry, **options):
305305
Responsibility for this piece of clean-up has been shifted to a custom class.
306306
307307
"""
308-
from pint.formatting import _FORMATTERS
309-
return _FORMATTERS["D"](unit, registry, **options)
308+
try: # Informal route changed in 0.22
309+
from pint.formatting import _FORMATTERS
310+
formatter = _FORMATTERS["D"]
311+
except ImportError: # pragma: no cover
312+
from pint import Unit
313+
formatter_obj = registry.formatter._formatters["D"]
314+
315+
def _surrogate_formatter(unit, registry, **options):
316+
try:
317+
parsed = Unit(unit)
318+
return formatter_obj.format_unit(parsed)
319+
except ValueError:
320+
parsed = Unit(unit)
321+
return formatter_obj.format_quantity(unit)
322+
323+
formatter = _surrogate_formatter
324+
325+
return formatter(unit, registry, **options)
310326

311327

312328
@functools.lru_cache(maxsize=1024)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'tests.units': ['test_units.txt']
3434
},
3535
install_requires=[
36-
"pint>=0.21,<0.24",
36+
"pint>=0.21,<0.25,!=0.22,!=0.23", # pint 0.22,0.23 have a bad interaction w/ numpy >= 2
3737
"deprecation>=2.1.0,<3",
3838
"typing_extensions>=4.8,<5",
3939
"importlib-resources>=5.3,<7"
@@ -52,7 +52,7 @@
5252
"pandas>=2.0.3,<3"
5353
],
5454
"tests.entity.bounds": [
55-
"numpy>=1.24.4,<2",
55+
"numpy>=1.24.4,<3",
5656
"pandas>=2.0.3,<3"
5757
]
5858
},

test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ flake8==7.0.0
22
flake8-docstrings==1.7.0
33
pytest==8.0.0
44
pytest-cov==4.1.0
5-
pandas>=2.0.3,<2.2.0
5+
pandas>=2.0.3,<2.2.0 # includes a compatible version of numpy
66
derp==0.1.1

tests/units/test_parser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,12 @@ def test_deprecation():
222222
megapascals = parse_units("MPa", return_unit=True)
223223
with pytest.warns(DeprecatedWarning):
224224
stringified = f"{megapascals:clean}"
225-
assert megapascals == parse_units(stringified, return_unit=True)
225+
assert megapascals == parse_units(stringified, return_unit=False)
226+
227+
from pint import Quantity
228+
with pytest.warns(DeprecatedWarning):
229+
assert f"{Quantity('5 MPa'):clean}" == f"5 {stringified}"
230+
231+
from pint import Unit
232+
with pytest.warns(DeprecatedWarning):
233+
assert f"{Unit('MPa'):clean}" == stringified

0 commit comments

Comments
 (0)