-
Notifications
You must be signed in to change notification settings - Fork 474
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
What does registry=None
mean in custom formatter ?
#2009
Comments
First, sorry for breaking things. The move to the new Formatter delegate allows more flexibility so I think this annoyance will pay off. Let me answer each of your questions:
The idea would be to make this function look and instantiate the registered formatters. def get_formatter(self, spec: str):
if spec == "":
return self._formatters["D"]
for k, v in self._formatters.items():
if k in spec:
return v
try:
orphan_fmt = REGISTERED_FORMATTERS[spec]
except KeyError:
return self._formatters["D"]
try:
fmt = orphan_fmt.__class__(self._registry)
spec = get_attr(fmt, "spec", spec)
self._formatters[spec] = fmt
return fmt
except:
return orphan_fmt |
and then also add the spec attribute to |
On a second thought |
I think I understand, thanks! I think I can try to suggest these changes in a PR if that helps. |
That would be great. I have review the code, it is necessary to add |
Hi!
With pint 0.24, the internal workings of
register_unit_format
have changed and theregistry
argument of the wrapped function can now be "None". I do not see in the doc the meaning of that new possible value. Wouldn't aUnit
object always be related to a registry, even if it's the default one ?This is causing issues in
cf-xarray
(and downstream) for example (xarray-contrib/cf-xarray#507) where we usedregistry
to convert theUnitContainer
back to aUnit
(see https://github.com/xarray-contrib/cf-xarray/blob/24dd81b2748db59c3ede68735a200b63b8a3d2d2/cf_xarray/units.py#L17-L38)EDIT: Also, the way
register_unit_format
is written, wouldn'tregistry
always be None ?The text was updated successfully, but these errors were encountered: