Skip to content
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

Different-registries error after pickle dump-load #725

Closed
jbriales opened this issue Oct 23, 2018 · 4 comments
Closed

Different-registries error after pickle dump-load #725

jbriales opened this issue Oct 23, 2018 · 4 comments

Comments

@jbriales
Copy link

I have saved a pint Quantity into a file with pickle.dump(...) then loaded it in a different program execution with pickle.load(...).
In both program executions I create the UnitRegistry in exactly the same way.
However, when comparing or mixing a Quantity that is obtained from the .pkl file via pickle.load(...) and a Quantity that is created in the current program execution via the UnitRegistry, I get the error:

ValueError: Cannot operate with Unit and Unit of different registries.

Following the instructions in the tutorial,
my understanding is that in this circumstances everything should work fine. What may be the problem or my misunderstanding?

@hgrecco
Copy link
Owner

hgrecco commented Oct 25, 2018

You need to set the application registry. We are currently reworking this to make it more user friendly,.

@jbriales
Copy link
Author

Set the application registry how?
My current two lines are

from pint import UnitRegistry
units = UnitRegistry(auto_reduce_dimensions=False)

then use units everywhere. Also, what's the best way to keep track of any updates to the API affecting this? (I would like to replace some hacks I did to deal with this when possible).
Basically, the hack I did for now was value = units.Quantity.from_tuple(value.to_tuple())

@iankharris
Copy link

iankharris commented Nov 24, 2018

After some digging, it looks like this is very straightforward:
pint.set_application_registry(ureg)

@hgrecco
Copy link
Owner

hgrecco commented Dec 4, 2019

This should be fixed in master.

@hgrecco hgrecco closed this as completed Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants