-
Notifications
You must be signed in to change notification settings - Fork 49
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
unable to use custom unit_registry nor modify base_value for unit in default_unit_registry #473
Comments
And yes, for issue 1 I've tried replacing |
Hi @AdamCohan Issue 1The bug is in your code sample itself, not unyt: if you create a new unit via a custom instance of
This is how you do it: from unyt import Unit
u = Unit("bushel", registry=my_registry) See https://unyt.readthedocs.io/en/stable/usage.html#unit-registries Issue 2
I'm not 100% sure whether this is a bug or a feature actually. Modifying the base value of a unit in the default registry seems risky, and it's not something that we seem to support (there are no tests for it at the moment). Whatever the intended behaviour is, I can see there's room for improvement in unyt since at the moment, it just silently refuses to follow your instructions; I think it should either be allowed or raise an explicit error. @jzuhone do you have opinions here ? |
We shouldn't allow modifying the |
This worked, thank you. |
I am having having an issue similar to issue 2 where instead of using the default_unit_registry I am using a custom one but it still isn't being modified:
|
To clarify, with additional print statements I can tell that the registry is being modified, but for whatever reason the Unit constructor isn't using the updated value |
I think it's an issue with the registry not being reloaded, because if I run |
interesting, then I think that's another bug we need to deal with. I'll try to give it a go. |
Sorry I shouldn't have jumped to conclusions. With a little more time to think about it I don't think this is actually a bug; if you modify the base value of a unit, you also change the value of any previously defined quantities attached to that unit, because Unit objects retrieved from a registry are singletons: there's only one of each, hence modifying its definition affects all its users. This may not match you expectations but I think this is the intended behaviour. Maybe @jzuhone can confirm or infirm my reasoning. |
Maybe we can help you with what you're trying to accomplish if you give us a little more details. |
If I understand what you're saying correctly then I think both of the |
If instead the second block looks like this:
then everything seems to work as I would expect it to, where |
you're right, that is what I'd expect indeed. Somehow I missed that, thanks for pointing it out.
You're not. Your reasoning makes sense to me and I agree now that the |
I've identified a bug in caching as the source of the current behaviour. #476 addresses it |
Description
I have two issues. The first is when creating a custom unit_registry I can't seem to be able to be able to push the changes in any meaningful way to use the units in said registry. The second is when adding custom units to the default unit registry, I can't modify the base_value after the fact.
What I Did
The text was updated successfully, but these errors were encountered: