-
Notifications
You must be signed in to change notification settings - Fork 13
add a module-global registry #32
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
Conversation
I'm still not sure if this API is a good choice, but i guess for now it's ready for reviews. |
After thinking about this some more I realized that the changes in this PR might not be optimal: it introduces its own "application registry", but if every library chose that approach they wouldn't be able to work together (see also Unidata/MetPy#1350) So I guess we need to either:
where changing the registry would require a If I'm honest, I'd prefer option 1 (change on import) since that would avoid boilerplate code but it might also lead to incompatible registries. The next best option might be a combination of 2 and 3? Not sure if it would help, but maybe we can have some sort of |
with the recent changes, the default registry is the application registry, which is changed on import (option 1a and 2b, I guess?). Even if this turns out to be undesirable it shouldn't be too difficult to change. |
This still doesn't solve the issue of multiple libraries requesting conflicting settings, but maybe we should wait until someone runs into this? If so I guess I'm content with the way it is right now, and I'll merge in a few days. It would be good to have at least one review, though. @dcherian, maybe? |
alright, I'm merging. As I said before, |
@keewis Thanks for taking the lead on this and I agree with your assessment. Also, my apologies for my continued inattentiveness on reviews here, the past couple months have been particularly difficult to keep up with things. I hope to get back to helping out more on these things in early December after the fall semester wraps up. Until then, don't worry about me in pushing forward with anything here! |
This is an attempt to fix the registry creation as discussed in #7. It will make sure that the selected registry is usable (i.e
force_ndarray_like
orforce_ndarray
are set) and that only a single registry is used. To makeds.pint.quantify()
work without any boilerplate code, it also introduces a module-global unit registry (pint_xarray.unit_registry
). For now, if someone wants a different unit registry, they need to call.quantify
with that registry – subsequent calls to.quantify
on the same object will then use that registry and reject other registries – or maybe setI'm not quite sure if this is a good API so this is a draft for now.