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: add parameter strict to assert_equal #24770

Merged
merged 1 commit into from Oct 2, 2023
Merged

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Sep 21, 2023

This adds the parameter strict to np.testing.assert_equal. With strict=True, the shape and dtype of the two arguments must match for the assertion to pass.

Follows the example of #21595
Partially addresses suggestion in #24667 (comment)
Addresses #24680 (comment)

This adds the parameter strict to np.testing.assert_equal. With strict=True, the shape and dtype of the two arguments must match for the assertion to pass.
@mdhaber mdhaber changed the title ENH: add parameter 'strict' to assert_equal ENH: add parameter strict to assert_equal Sep 21, 2023
@@ -232,22 +232,22 @@ def test_array_vs_scalar_strict(self):
b = 1.

with pytest.raises(AssertionError):
assert_array_equal(a, b, strict=True)
self._assert_func(a, b, strict=True)
Copy link
Contributor Author

@mdhaber mdhaber Sep 21, 2023

Choose a reason for hiding this comment

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

TestEqual, the class used to test assert_equal, inherits from this class. This class is TestArrayEqual, which is used to test assert_array_equal.)

Before this PR, these three tests of the strict parameter would run twice - once for TestArrayEqual, and once for TestEqual - but assert_array_equal was tested both times. Now, these will test the appropriate assertion function each time they run.

These were the only tests of the strict parameter added when the strict parameter was added to assert_array_equal in gh-21595. If they were sufficient there, hopefully enabling them for assert_equal is sufficient here.

@mdhaber
Copy link
Contributor Author

mdhaber commented Sep 21, 2023

If this needs corrections, LMK if I should add the strict parameter to assert_array_less at the same time. As in the assert_allclose (gh-24680), it would just need to pass the argument along to assert_array_compare. I went ahead and created gh-24775. I'll wait before doing any more.

@mattip
Copy link
Member

mattip commented Oct 1, 2023

LGTM. I will merge it soon if no-one else has any comments.

@mattip mattip merged commit 5ca26b1 into numpy:main Oct 2, 2023
51 checks passed
@mattip
Copy link
Member

mattip commented Oct 2, 2023

Thanks @mdhaber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants