dylanwal / unit_parse

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

unit_parse does not support parsing percentages #10

Open bramp opened 3 days ago

bramp commented 3 days ago

Pint supports percentage values, but unit_parse.parse returns None.

import unit_parse

print(unit_parse.parser("10"))    # Prints 10 
print(unit_parse.parser("10%")) # Prints None

import pint

ureg = pint.UnitRegistry()
print(10 * ureg.percent).                 # Prints 10 percent
print(10 * ureg.parse_units("%"))  # Prints 10 percent

Please support parsing of "10%". Thanks

bramp commented 3 days ago

Ah it seems to be this line: https://github.com/dylanwal/unit_parse/blob/master/src/unit_parse/config.py#L117, [0-9]{1,5} ?% that explicitly replaces any number string ending in % with "".

Removing that line fixes my use case, but seems to break your tests.