dylanwal / unit_parse

Tool for parsing 'ugly' numbers and units
BSD 3-Clause "New" or "Revised" License
11 stars 3 forks source link

"Derived dimensions cannot have aliases." if pint is updated #9

Closed bramp closed 2 months ago

bramp commented 3 months ago

tl;dr: Two problems, firstly, unit_parse doesn't work with the latest python + numpy, due to a issue in pint. If I upgrade pint, then unit_parse fails due to outdated support_files.

Very simple program:

import unit_parse

print(unit_parse.parser("1.5 kg"))

fails with:

  File ".venv/lib/python3.12/site-packages/numpy/__init__.py", line 410, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'cumproduct'. Did you mean: 'cumprod'?

which seems to be because of https://github.com/hgrecco/pint/issues/1974, python 3 + numpy 2 + pint don't play nicely. They fixed it in pint 0.24.1, so pip install pint=0.24.1

now fails with:

pint.delegates.txt_defparser.common.DefinitionSyntaxError: Derived dimensions cannot have aliases.
    231,0-231,40 [velocity] = [length] / [time] = [speed]
    .venv/lib/python3.12/site-packages/unit_parse/support_files/constants_en.txt

It seems the support_files/constants_en.txt and support_files/default_en.txt are not the same as the ones that now come with pint. If I update them, everything now works correctly.

Is there any reason unit_parse bundles these files? and doesn't just create a default pint registry? Happy to send a pull request to fix this by either updating the bundled files, or changing to use a default pint setup.