-
Notifications
You must be signed in to change notification settings - Fork 485
Closed
Description
Combining a custom format registered with @pint.register_unit_format
and a modifier does not work on 0.24 any more. Apparently the formatter is silently not even called.
import pint
ureg = pint.get_application_registry().get()
@pint.register_unit_format("test")
def _test_format(unit, registry, **options):
print("format called")
proc = {u.replace("µ", "u"): e for u, e in unit.items()}
fmt = pint.formatting if hasattr(pint, "formatting") else pint
return fmt.formatter(
proc.items(),
as_ratio=True,
single_denominator=False,
product_fmt="*",
division_fmt="/",
power_fmt="{}{}",
parentheses_fmt="({})",
**options,
)
base_unit = ureg.microsecond
print(f"with modifier - {base_unit:~test}")
print(f"without modifier - {base_unit:test}")
Output on pint 0.23
format called
with modifier - us
format called
without modifier - microsecond
Output on pint 0.24
with modifier - µs
format called
without modifier - microsecond
unfortunately we currently have to still support python 3.9, so only supporting pint 0.24+ is not an option for us, our code has to work on both versions... :-(
Metadata
Metadata
Assignees
Labels
No labels