-
Notifications
You must be signed in to change notification settings - Fork 476
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
quantities created using pint.Quantity
are inconsistent
#1749
Comments
Since the beginning, it was decided that the registry should not be a singleton within the package, but rather a normal object that the user should instantiate. No magic. We later relaxed this idea by creating the default registry and making some magic. In retrospect, not sure that this was a good idea. On top, we now create a specific Quantity class for each type of registry. One way of solving this might by adding the Quantity class to the application registry within def __new__(cls, *args, **kwargs):
inst = object.__new__(cls)
if not hasattr(cls, "_REGISTRY"):
# Base class, not subclasses dynamically by
# UnitRegistry._init_dynamic_classes
from . import application_registry
inst._REGISTRY = application_registry.get()
return inst to this: def __new__(cls, *args, **kwargs):
if not hasattr(cls, "_REGISTRY"):
# Base class, not subclasses dynamically by
# UnitRegistry._init_dynamic_classes
from . import application_registry
cls._REGISTRY = application_registry.get()
return object.__new__(cls) or something similar (haven't tested) In general, I would say that any non-trivial use of Pint within a library should use only the What do you think? |
that is true, but since the recent change to support registries other than the application registry with |
We can support changing the registry as long as dask does not hold a reference directly to Quantity/Unit. Maybe we can review the code together. |
Consider this:
We can see that the type returned using
pint.Quantity
(which is an alias ofpint.UnitRegistry.Quantity
, i.e. the class member) claims to be created from the application registry but has a different type from quantities directly created from the application registry.I'm not sure how to debug this, especially since commenting out / relocating the alias definitions for
Quantity
,Unit
,Measurement
, andContext
in the main module seems to cause the instantiation of_DEFAULT
(theLazyRegistry
instance) to fail. Any ideas, @hgrecco?For more context, this has been exposed in
xarray
's test suite by #1722, before that it would automatically change the registry (and type) to the application registry.The text was updated successfully, but these errors were encountered: