-
Notifications
You must be signed in to change notification settings - Fork 504
to_compact is broken for Measurements and for Quantitys with uncertainties #2044
Copy link
Copy link
Closed
Description
I'm using uncertainties 3.2.2, and pint 0.24.3, and I want to use to_compact for measurements, and it fails. Here's a MWE demonstrating two methods I tried:
import uncertainties
import pint
ureg = pint.UnitRegistry()
v = 1.24
s = 0.01
# Fails
print((v * ureg.Hz).plus_minus(s).to_compact())
# Also fails
print((uncertainties.ufloat(v, s)*ureg.Hz).to_compact())Fails with:
Traceback (most recent call last):
File "/home/doron/repos/lab-ion-trap-simulations/mwe.py", line 12, in <module>
print((uncertainties.ufloat(v, s)*ureg.Hz).to_compact())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/zw5lasilw5gacg56s0rgnazdng3vby2i-python3-3.12.4-env/lib/python3.12/site-packages/pint/facets/plain/qto.py", line 116, in to_compact
or math.isnan(quantity.magnitude)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/zw5lasilw5gacg56s0rgnazdng3vby2i-python3-3.12.4-env/lib/python3.12/site-packages/uncertainties/core.py", line 2611, in raise_error
raise TypeError("can't convert an affine function (%s)"
TypeError: can't convert an affine function (<class 'uncertainties.core.AffineScalarFunc'>) to float; use x.nominal_value
I tested this MWE with multiple uncertainties versions 3.2.2, 3.2.0 and 3.1.7 and all of them didn't fail when pint was downgraded to 0.23, and failed when pint was at version 0.24 and 0.24.1.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels