Skip to content

BUG: array_namespace returns compat for NumPy scalars with use_compat=None #164

Closed
@lucascolley

Description

@lucascolley

With array-api-compat 1.8, NumPy 2.0.1

In [22]: array_namespace(np.asarray(0.0), use_compat=None)
Out[22]: <module 'numpy' from '/Users/lucascolley/mambaforge/envs/scipy-dev/lib/python3.10/site-packages/numpy/__init__.py'>

In [23]: array_namespace(np.float64(0.0), use_compat=None)
Out[23]: <module 'scipy._lib.array_api_compat.numpy' from '/Users/lucascolley/programming/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/array_api_compat/numpy/__init__.py'>

This behaviour is quite problematic for SciPy given NumPy's tendency to throw NumPy scalars at you under very little pressure.

In [25]: array_namespace(np.asarray(0.0) - 32, use_compat=None)
Out[25]: <module 'scipy._lib.array_api_compat.numpy' from '/Users/lucascolley/programming/scipy/build-install/lib/python3.10/site-packages/scipy/_lib/array_api_compat/numpy/__init__.py'>

It seems practical to have NumPy scalars return the same namespace as NumPy arrays when use_compat=None. Or perhaps a different argument should have to be passed to use_compat (that would be fine for us).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions