Skip to content

Commit bfd3b34

Browse files
add nominal_value to measurements after they were removed from pint, ensure unit registry formatting avoids deprecation
1 parent cf4fb77 commit bfd3b34

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

mpcontribs-api/mpcontribs/api/contributions/document.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
lambda s: s.replace("%", " percent "),
3434
],
3535
)
36-
ureg.default_format = "~,P"
36+
ureg.formatter.default_format = "~,P"
3737

3838
if "percent" not in ureg:
3939
# percent is native in pint >= 0.21
@@ -100,7 +100,10 @@ def get_quantity(s):
100100

101101
try:
102102
parts[0] = ufloat_fromstr(parts[0])
103-
return ureg.Measurement(*parts)
103+
meas = ureg.Measurement(*parts)
104+
if not hasattr(meas,"nominal_value") and (val := hasattr(meas,"value")):
105+
meas.nominal_value = float(val) # Measurement.value is a `Quantity` object
106+
return meas
104107
except ValueError:
105108
return None
106109

0 commit comments

Comments
 (0)