-
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
BUG: fix an issue where array functions would raise UnitConsistencyError on unyt arrays using non-default unit registries #463
Conversation
…ror on unyt arrays using non-default unit registries
c57f31d
to
9dbd8ec
Compare
sunits = set(units) | ||
if len(sunits) == 1: | ||
unique_units = set(units) | ||
if len(unique_units) == 1 or all(u.is_dimensionless for u in unique_units): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain a little bit more how this resolves the issue (sorry, it may be because it's late for me)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem was that
Unit()
andUnit(registry=UnitRegistry())
have different hash, so they are considered as 2 separate unique unitsUnit()
(orNULL_UNIT
is this context) gets automatically inserted for non-unyt array-like data structures only because we want them to be treated as dimensionless
This condition makes it so all dimensionless units are treated as equal as long as nothing else is received.
What happens if the unit is dimensionless but is not the |
that's good question. I think we should replicate the behaviour of basic operations (like addition), which I believe my current patch does. At the moment, |
@neutrinoceros they are equal--I just checked: import unyt as u
a = 1+1.0*u.Zsun
b = 1.0*u.Zsun+1
print(a)
print(b)
print(a == b) gives: 1.01295 dimensionless
78.22007722007721 Zsun
True |
Address the first part of #462