Skip to content

ENH: add parameter strict to assert_allclose#24680

Merged
mattip merged 3 commits into
numpy:mainfrom
mdhaber:gh21595
Sep 21, 2023
Merged

ENH: add parameter strict to assert_allclose#24680
mattip merged 3 commits into
numpy:mainfrom
mdhaber:gh21595

Conversation

@mdhaber

@mdhaber mdhaber commented Sep 10, 2023

Copy link
Copy Markdown
Contributor

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

Follows the example of gh-21595
Partially addresses suggestion in #24667 (comment)

@mdhaber mdhaber left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To fix the CircleCI failure.

Comment thread numpy/testing/_private/utils.py Outdated
Comment thread numpy/testing/_private/utils.py Outdated
@mdhaber

mdhaber commented Sep 11, 2023

Copy link
Copy Markdown
Contributor Author

IIUC, I should add a file doc/release/upcoming_changes/24680.new_feature.rst with contents like

``strict`` option for `testing.assert_allclose`
-----------------------------------------------
The ``strict`` option is now available for `testing.assert_allclose`.
Setting ``strict=True`` will disable the broadcasting behaviour for scalars and
ensure that input arrays have the same data type.

? I'll also commit the <BLANKLINE>s above and run CI with [skip actions] [skip cirrus] [skip azp]?

@seberg

seberg commented Sep 11, 2023

Copy link
Copy Markdown
Member

That seems about right, yes.

[skip actions] [skip cirrus] [skip azp]

@mdhaber mdhaber left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two minor tweaks for the reviewer to consider. Feel free to commit.
When this looks good, I'll submit a follow-up for assert_equal, if that would be helpful?
These will help address #24667 (comment).

Comment thread numpy/testing/_private/utils.py Outdated
Comment thread numpy/testing/_private/utils.py Outdated
@mattip

mattip commented Sep 21, 2023

Copy link
Copy Markdown
Member

@mdhaber Please go ahead and commit your self-review changes so we can get this in.

[skip actions] [skip cirrus] [skip azp]
@mdhaber

mdhaber commented Sep 21, 2023

Copy link
Copy Markdown
Contributor Author

Thanks @mattip. That rendered as intended.
When this merges, shall I do the same for assert_equal?

@mattip mattip merged commit 224b28f into numpy:main Sep 21, 2023
@mattip

mattip commented Sep 21, 2023

Copy link
Copy Markdown
Member

Thanks @mdhaber. Yes, I think assert_equal could also get a strict kwarg. At the same time, the docstring of assert_equal could use some touchup: it is missing the Notes and See Also that the others have.

@mdhaber

mdhaber commented Sep 30, 2023

Copy link
Copy Markdown
Contributor Author

@mattip I opened gh-24770 to add the strict kwarg to assert_equal and touch up the docs as you suggested. gh-24775 adds strict to assert_array_less.

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.

3 participants