Skip to content

TST: make xp_assert_{equal,close} scalar check opt-in #20959

@ev-br

Description

@ev-br
In [10]: from scipy._lib._array_api import xp_assert_close, xp_assert_equal

In [11]: a = np.array(42)

In [12]: xp_assert_equal(a, a)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[12], line 1
----> 1 xp_assert_equal(a, a)

    [... skipping hidden 2 frame]

File ~/repos/scipy/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/_array_api.py:290, in _check_scalar(actual, desired, xp)
    288 desired = desired[()]
    289 _msg = f"Types do not match:\n Actual: {type(actual)}\n Desired: {type(desired)}"
--> 290 assert (xp.isscalar(actual) and xp.isscalar(desired)
    291         or (not xp.isscalar(actual) and not xp.isscalar(desired))), _msg

AssertionError: Types do not match:
 Actual: <class 'numpy.ndarray'>
 Desired: <class 'numpy.int64'>

In [13]: xp_assert_close(a, a)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[13], line 1
----> 1 xp_assert_close(a, a)

    [... skipping hidden 2 frame]

File ~/repos/scipy/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/_array_api.py:290, in _check_scalar(actual, desired, xp)
    288 desired = desired[()]
    289 _msg = f"Types do not match:\n Actual: {type(actual)}\n Desired: {type(desired)}"
--> 290 assert (xp.isscalar(actual) and xp.isscalar(desired)
    291         or (not xp.isscalar(actual) and not xp.isscalar(desired))), _msg

AssertionError: Types do not match:
 Actual: <class 'numpy.ndarray'>
 Desired: <class 'numpy.int64'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    array typesItems related to array API support and input array validation (see gh-18286)duplicateIssues that describe the same problem or that are reported multiple timesmaintenanceItems related to regular maintenance tasksscipy._lib

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions