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

ENH: (NEP 18) test and implement combinatory functions #351

Merged
merged 2 commits into from
Jan 9, 2023

Conversation

neutrinoceros
Copy link
Member

Covers most of the functions last disscussed in #289 (comment)

@neutrinoceros neutrinoceros force-pushed the nep18_masks branch 2 times, most recently from ff8639c to 730eb51 Compare January 4, 2023 15:16
@neutrinoceros neutrinoceros marked this pull request as ready for review January 4, 2023 15:26
Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that some of the new errors that will get raised here will break downstream code in a somewhat annoying way. I would err on the side of only checking unit consistency if one of the arguments has a unit, otherwise if all arguments are numbers or ndarrays, assume that the arguments have units appropriate for the array.

unyt/tests/test_array_functions.py Outdated Show resolved Hide resolved
unyt/tests/test_array_functions.py Outdated Show resolved Hide resolved
unyt/_array_functions.py Outdated Show resolved Hide resolved
def test_clip_mixed_units():
a = [1, 2, 3, 4, 5, 6] * cm
with pytest.raises(UnitInconsistencyError):
np.clip(a, 3 * cm, 4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should error, but I kinda think np.clip(a, 3, 4) shouldn't error. The fact that it does now breaks existing unyt tests is another indicator that it shouldn't error, since it could just as easily break downstream user code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I kinda think np.clip(a, 3, 4) shouldn't error

me too TBH, but in that case it seems to me that making np.clip(a, 3 * cm, 4) error will add more complexity than it is worth.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind it's actually quite simple

unyt/tests/test_array_functions.py Outdated Show resolved Hide resolved
@neutrinoceros
Copy link
Member Author

I'm worried that some of the new errors that will get raised here will break downstream code in a somewhat annoying way. I would err on the side of only checking unit consistency if one of the arguments has a unit, otherwise if all arguments are numbers or ndarrays, assume that the arguments have units appropriate for the array.

That is also how I think it should work, and I agree that the fact that I had to change existing tests is indication that it's currently on the wrong track.
So to be clear in those cases I should treat pure numbers as if they had the appropriate units instead of treating them as dimensionless ?

@ngoldbaum
Copy link
Member

So to be clear in those cases I should treat pure numbers as if they had the appropriate units instead of treating them as dimensionless?

Yes, but again only if all of the arguments are pure numbers. If one of them has units, I think it makes sense to do unit checking.

@neutrinoceros
Copy link
Member Author

@ngoldbaum I just pushed a changeset that I think should resolved on-going discussions, however I need to make another pass tomorrow to make sure I've updated all other functions to be in line with the behaviour we want.

@neutrinoceros
Copy link
Member Author

Alright this is good for review again. To make changes easier to review I just pushed incremental changes, but
I would like my commits to get squashed before or on merge. I can do it with a rebase once we have converged on reviews, just please don't merge the branch in its current state.

@neutrinoceros neutrinoceros marked this pull request as ready for review January 5, 2023 11:37
unyt/testing.py Outdated
@@ -49,6 +51,12 @@ def assert_allclose_units(actual, desired, rtol=1e-7, atol=0, **kwargs):
raise AssertionError


def assert_array_equal_units(a, b):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it's in the public API it needs a docstring

@ngoldbaum
Copy link
Member

Sorry for not getting to this last friday. Other than the missing docstring this looks good to me. Please go ahead and squash the commits as you'd like :)

@neutrinoceros
Copy link
Member Author

No worries ! I'll try to get this finished this evening.

@neutrinoceros
Copy link
Member Author

@ngoldbaum I force-pushed with a compact history. The change you requested in now in the second commit. It's now ready for merging.

@ngoldbaum ngoldbaum merged commit 2d55916 into yt-project:main Jan 9, 2023
@neutrinoceros neutrinoceros deleted the nep18_masks branch January 9, 2023 21:16
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

Successfully merging this pull request may close these issues.

2 participants