Skip to content

DOC: Document assertion comparison behavior between scalar and empty array #29143

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ def assert_equal(actual, desired, err_msg='', verbose=True, *, strict=False):

Notes
-----
By default, when one of `actual` and `desired` is a scalar and the other is
an array, the function checks that each element of the array is equal to
the scalar. This behaviour can be disabled by setting ``strict==True``.
When one of `actual` and `desired` is a scalar and the other is array_like, the
function checks that each element of the array_like is equal to the scalar.
Note that empty arrays are therefore considered equal to scalars.
This behaviour can be disabled by setting ``strict==True``.

Examples
--------
Expand Down Expand Up @@ -980,9 +981,10 @@ def assert_array_equal(actual, desired, err_msg='', verbose=True, *,

Notes
-----
When one of `actual` and `desired` is a scalar and the other is array_like,
the function checks that each element of the array_like object is equal to
the scalar. This behaviour can be disabled with the `strict` parameter.
When one of `actual` and `desired` is a scalar and the other is array_like, the
function checks that each element of the array_like is equal to the scalar.
Note that empty arrays are therefore considered equal to scalars.
This behaviour can be disabled by setting ``strict==True``.

Examples
--------
Expand Down Expand Up @@ -1651,10 +1653,10 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,

Notes
-----
When one of `actual` and `desired` is a scalar and the other is
array_like, the function performs the comparison as if the scalar were
broadcasted to the shape of the array.
This behaviour can be disabled with the `strict` parameter.
When one of `actual` and `desired` is a scalar and the other is array_like, the
function performs the comparison as if the scalar were broadcasted to the shape
of the array. Note that empty arrays are therefore considered equal to scalars.
This behaviour can be disabled by setting ``strict==True``.

Examples
--------
Expand Down
Loading