Skip to content

The numpy.array_api namespace has been removed in numpy 2.0 #9019

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

Closed
5 tasks done
bnavigator opened this issue May 9, 2024 · 2 comments
Closed
5 tasks done

The numpy.array_api namespace has been removed in numpy 2.0 #9019

bnavigator opened this issue May 9, 2024 · 2 comments

Comments

@bnavigator
Copy link

bnavigator commented May 9, 2024

What happened?

https://numpy.org/devdocs/reference/array_api.html

NumPy 1.22.0 was the first version to include support for the array API standard, via a separate numpy.array_api submodule. This module was marked as experimental (it emitted a warning on import) and removed in NumPy 2.0 because full support was included in the main namespace.

What did you expect to happen?

Sucessful test suite with numpy 2.0.0rc1

Minimal Complete Verifiable Example

# pip install xarray 'numpy>=2.0.0rc1'
from xarray.namedarray import _array_api

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

[  159s] ____ TestNamedArray.test_expand_dims[None-3-expected_shape0-expected_dims0] ____
[  159s] [gw3] linux -- Python 3.10.14 /usr/bin/python3.10
[  159s] 
[  159s] self = <xarray.tests.test_namedarray.TestNamedArray object at 0x7f8ebeb98a00>
[  159s] target = <xarray.NamedArray (x: 2, y: 5)> Size: 80B
[  159s] array([[0. , 0.5, 1. , 1.5, 2. ],
[  159s]        [2.5, 3. , 3.5, 4. , 4.5]])
[  159s] dim = None, expected_ndim = 3, expected_shape = (1, 2, 5)
[  159s] expected_dims = (None, 'x', 'y')
[  159s] 
[  159s]     @pytest.mark.parametrize(
[  159s]         "dim,expected_ndim,expected_shape,expected_dims",
[  159s]         [
[  159s]             (None, 3, (1, 2, 5), (None, "x", "y")),
[  159s]             (_default, 3, (1, 2, 5), ("dim_2", "x", "y")),
[  159s]             ("z", 3, (1, 2, 5), ("z", "x", "y")),
[  159s]         ],
[  159s]     )
[  159s]     def test_expand_dims(
[  159s]         self,
[  159s]         target: NamedArray[Any, np.dtype[np.float32]],
[  159s]         dim: _Dim | Default,
[  159s]         expected_ndim: int,
[  159s]         expected_shape: _ShapeLike,
[  159s]         expected_dims: _DimsLike,
[  159s]     ) -> None:
[  159s] >       result = target.expand_dims(dim=dim)
[  159s] 
[  159s] /home/abuild/rpmbuild/BUILD/xarray-2024.03.0/xarray/tests/test_namedarray.py:508: 
[  159s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  159s] /home/abuild/rpmbuild/BUILD/xarray-2024.03.0/xarray/namedarray/core.py:1127: in expand_dims
[  159s]     from xarray.namedarray._array_api import expand_dims
[  159s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  159s] 
[  159s]     from __future__ import annotations
[  159s]     
[  159s]     import warnings
[  159s]     from types import ModuleType
[  159s]     from typing import Any
[  159s]     
[  159s]     import numpy as np
[  159s]     
[  159s]     from xarray.namedarray._typing import (
[  159s]         Default,
[  159s]         _arrayapi,
[  159s]         _Axes,
[  159s]         _Axis,
[  159s]         _default,
[  159s]         _Dim,
[  159s]         _DType,
[  159s]         _ScalarType,
[  159s]         _ShapeType,
[  159s]         _SupportsImag,
[  159s]         _SupportsReal,
[  159s]     )
[  159s]     from xarray.namedarray.core import NamedArray
[  159s]     
[  159s]     with warnings.catch_warnings():
[  159s]         warnings.filterwarnings(
[  159s]             "ignore",
[  159s]             r"The numpy.array_api submodule is still experimental",
[  159s]             category=UserWarning,
[  159s]         )
[  159s] >       import numpy.array_api as nxp  # noqa: F401
[  159s] E       ModuleNotFoundError: No module named 'numpy.array_api'
[  159s] 
[  159s] /home/abuild/rpmbuild/BUILD/xarray-2024.03.0/xarray/namedarray/_array_api.py:30: ModuleNotFoundError



Python 3.11.9 (main, Apr 08 2024, 06:18:15) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from xarray.namedarray import _array_api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/xarraymin/lib64/python3.11/site-packages/xarray/namedarray/_array_api.py", line 30, in <module>
    import numpy.array_api as nxp  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'numpy.array_api'

Anything else we need to know?

No response

Environment

/tmp/xarraymin/lib64/python3.11/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit: None
python: 3.11.9 (main, Apr 08 2024, 06:18:15) [GCC]
python-bits: 64
OS: Linux
OS-release: 6.8.7-1-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8
LOCALE: ('de_DE', 'UTF-8')
libhdf5: None
libnetcdf: None

xarray: 2024.3.0
pandas: 2.2.2
numpy: 2.0.0rc1
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.5.0
pip: 24.0
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None

@bnavigator bnavigator added bug needs triage Issue that has not been reviewed by xarray team member labels May 9, 2024
Copy link

welcome bot commented May 9, 2024

Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!

@keewis keewis added duplicate and removed bug needs triage Issue that has not been reviewed by xarray team member labels May 9, 2024
@keewis
Copy link
Collaborator

keewis commented May 9, 2024

Thanks for the report. This will be fixed by #8854, and the tracking issue is #8844. As such, I'll close this as a duplicate.

@keewis keewis closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants