0

This is the first time I'm creating my own units in the Pint registry. I'm trying to custom define sucrose units. Mostly density. Can Pint handle more complex calculations than just basic math? It's just addition/multiplication, but the order-of-operations () may be the issue?

I'm defining specific gravity as the standard for sucrose to be:

PINT_UNIT_REGISTER = UnitRegistry()
PINT_UNIT_REGISTER.define('SpecificGravity = [Sucrose] = sg')

then, I want to create degrees Brix:


PINT_UNIT_REGISTER.define('Brix = (((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622) = bx')

But, getting the following error, which implies Pint can't parse this. Basic math works fine, but as soon as I introduce ordering parenthesis, it fails. Any workarounds?

  File "/Users/aaronpaxson/PycharmProjects/stonesrivermeadery-webroot/stonesrivermeadery/settings.py", line 181, in <module>
    PINT_UNIT_REGISTER.define('Brix = (((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622) = Bx')
  File "/Users/aaronpaxson/PycharmProjects/stonesrivermeadery-webroot/venv/lib/python3.9/site-packages/pint/facets/plain/registry.py", line 428, in define
    self._helper_dispatch_adder(definition)
  File "/Users/aaronpaxson/PycharmProjects/stonesrivermeadery-webroot/venv/lib/python3.9/site-packages/pint/facets/plain/registry.py", line 447, in _helper_dispatch_adder
    raise TypeError(
TypeError: No loader function defined for UnhandledParsingError

0 Answers0