Skip to content

Rework prepare_for_test #2

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

Merged
merged 4 commits into from
Apr 25, 2025

Conversation

crusaderky
Copy link

@crusaderky crusaderky commented Apr 25, 2025

Part of review of data-apis#267
(change only in last commit; everything else is a merge from main)

Copy link
Owner

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

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

A lot of these changes are tweaks to the original code. Did you change your mind about the best variable/function names, docstrings, order, etc.?

Comment on lines +226 to +233
if rtol is None:
if xp.isdtype(actual.dtype, ("real floating", "complex floating")):
# multiplier of 4 is used as for `np.float64` this puts the default `rtol`
# roughly half way between sqrt(eps) and the default for
# `numpy.testing.assert_allclose`, 1e-7
rtol = xp.finfo(actual.dtype).eps ** 0.5 * 4
else:
rtol = 1e-7
Copy link
Owner

Choose a reason for hiding this comment

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

To save microseconds in a test?

Copy link
Author

Choose a reason for hiding this comment

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

No, it was an attempt to convince pyright. Regardless, I think it's slightly cleaner this way.

Comment on lines +235 to +236
actual_np = as_numpy_array(actual, xp=xp)
desired_np = as_numpy_array(desired, xp=xp)
Copy link
Owner

Choose a reason for hiding this comment

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

Is this fixing a pyright issue?

Copy link
Author

Choose a reason for hiding this comment

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

In data-apis#267 all testing becomes done exclusively by numpy.
So it makes sense to push the conversion into this function.
As a cascade effect, this makes type validation on behalf of pyright a lot easier.

@mdhaber mdhaber changed the base branch from xp_assert_enhancements to main April 25, 2025 16:21
@mdhaber mdhaber changed the base branch from main to xp_assert_enhancements April 25, 2025 16:21
@mdhaber
Copy link
Owner

mdhaber commented Apr 25, 2025

Shoot, that was supposed to just confirm that the other 16 commits were just a merge. Can you resolve the merge conflicts? I think all you need to do is accept --yours.

@crusaderky
Copy link
Author

Shoot, that was supposed to just confirm that the other 16 commits were just a merge. Can you resolve the merge conflicts? I think all you need to do is accept --yours.

done

@mdhaber mdhaber merged commit cb3c2d6 into mdhaber:xp_assert_enhancements Apr 25, 2025
@crusaderky crusaderky deleted the prepare_for_test branch April 25, 2025 16:30
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