-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
formats, documentation and custom formats #1357
Comments
I like this proposal. I was wondering for a time if there should provide some kind of templating engine but it way to broad, I think. So I then thought about allowing |
great, I'll look into implementing |
Regarding Right now those dicts are the kw of So I think we could do something like this @pint.register_unit_format("P")
def format_units_pretty(units, modifier):
### SOME CODE
return formatter(units.items(),
as_ratio=True,
single_denominator=False,
product_fmt= "·",
division_fmt= "/",
power_fmt= "{}{}",
parentheses_fmt= "({})",
exp_call= _pretty_fmt_exponent,
) (I am not puting here the modifier for simplicity) |
A related issue/motivation is that if I have a with fractional units 2/3, and then ureg(str(a)) != a because of the default exp_call=lambda x: f"{x:n}". |
I think there are several issues with unit formatting right now:
Related to xarray-contrib/pint-xarray#121: whenever I need to format units, rather than the documentation I tend to look through the source code of
pint.formatting
, especially_FORMATS
is useful. This, I think, is because the documentation of the format values is hidden pretty well (the only mention I can find is in the tutorial which is incomplete, i.e. some of the formats and the quantity modifer"#"
are never mentioned).I also think the default format (
""
in_FORMATS
) should get a actual name: if I setUnitRegistry.default_format = "P"
, the "default format" as defined in_FORMATS
is not accessible anymore until I set the registry's default back to""
.Finally, it would be great to have some kind of mechanism to register custom formats (we already can modify
pint.formatting._FORMATS
, but that's a implementation detail, right?). The syntax could bewhere the register function should make sure it does not overwrite already existing formats.
Not sure if it would be better to open separate issues for each of these, but I though it might make sense to consider them together.
The text was updated successfully, but these errors were encountered: