-
Notifications
You must be signed in to change notification settings - Fork 12
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
Create global reference to default registry on import? #7
Comments
It looks like in order to resolve #26 we need to resolve (and document) this first. We currently have pint-xarray/pint_xarray/accessors.py Lines 90 to 97 in acd1874
Dataset with units from different unit registries using multiple calls to quantify ; we should make that something that has to be explicitly requested.
In order to do so, we might need to either mutate the current application registry, create a new application registry, or save the registry in a module global (but I'm sure I'm missing a cleaner way). Thoughts? |
thinking about this some more, there are a few cases that might be useful to consider here:
Thoughts, @TomNicholas, @jthielen? |
My thoughts on this would be roughly similar to yours @keewis, with one main difference:
|
I definitely agree with point 3. However, while your suggestion in point 2 to raise instead of modifying the application registry is cleaner, it also means that users always have to modify / overwrite the application registry before being able to use import pint
import pint_xarray
import xarray as xr
pint.set_application_registry(pint.UnitRegistry(force_ndarray_like=True))
# might also work:
# pint.get_application_registry().force_ndarray_like = True Not sure what the best way to fix that is, maybe a module-global unit registry ( Point 1 is not also quite clear to me, which might be because I don't really understand in which situation one would need multiple registries. We could probably exclude support for multiple registries for now and change that in the future? |
I didn't realise that there are functions for getting and setting a global pint registry (see pint/#880).
For xarray integration, the ideal eventual usage in my opinion would be to enable pint-xarray by default when both pint and xarray are imported, and pint-xarray is installed, so you only need do
Not having to do
would be nice I think.
But that would mean initialising the default registry either during
quantify
, or during the module imports.set_application_registry()
means that particular users can still change it after imports, andget_application_registry()
can be called from withinquantify
calls.The text was updated successfully, but these errors were encountered: