Skip to content
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

xarray error with numpy > 2.0 on import #404

Open
cgrdn opened this issue Oct 25, 2024 · 1 comment
Open

xarray error with numpy > 2.0 on import #404

cgrdn opened this issue Oct 25, 2024 · 1 comment

Comments

@cgrdn
Copy link

cgrdn commented Oct 25, 2024

I am unsure action is required on this but I thought it might be nice to know.

I have just installed argopy 1.0.0 in a relatively fresh conda env. On import I received an error traceback to xarray having to do with calling np.unicode_ as it was deprecated in numpy 2.0. I then installed/re-installed xarray which downgraded numpy from 2.1.2 to 1.26.4 and solved the issue. Worth noting I had a similar issue with another package and numpy earlier.

MCVE Code Sample

conda install -c conda-forge argopy

Retrieving notices: ...working... done
Channels:
 - conda-forge
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\gordonc\AppData\Local\anaconda3\envs\admt25

  added / updated specs:
    - argopy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    aiohappyeyeballs-2.4.3     |     pyhd8ed1ab_0          19 KB  conda-forge
    aiohttp-3.10.10            |  py312h31fea79_0         778 KB  conda-forge
    aiosignal-1.3.1            |     pyhd8ed1ab_0          12 KB  conda-forge
    anyio-4.6.2.post1          |     pyhd8ed1ab_0         107 KB  conda-forge
    argopy-1.0.0               |     pyhd8ed1ab_0         203 KB  conda-forge
    attrs-24.2.0               |     pyh71513ae_0          55 KB  conda-forge
    brotli-python-1.1.0        |  py312h275cf98_2         314 KB  conda-forge
    cffi-1.17.1                |  py312h4389bb4_0         281 KB  conda-forge
    charset-normalizer-3.4.0   |     pyhd8ed1ab_0          46 KB  conda-forge
    erddapy-2.2.3              |     pyhd8ed1ab_0          25 KB  conda-forge
    exceptiongroup-1.2.2       |     pyhd8ed1ab_0          20 KB  conda-forge
    frozenlist-1.5.0           |  py312h4389bb4_0          53 KB  conda-forge
    fsspec-2024.10.0           |     pyhff2d567_0         132 KB  conda-forge
    h11-0.14.0                 |     pyhd8ed1ab_0          47 KB  conda-forge
    h2-4.1.0                   |     pyhd8ed1ab_0          46 KB  conda-forge
    hpack-4.0.0                |     pyh9f0ad1d_0          25 KB  conda-forge
    httpcore-1.0.6             |     pyhd8ed1ab_0          45 KB  conda-forge
    httpx-0.27.2               |     pyhd8ed1ab_0          64 KB  conda-forge
    hyperframe-6.0.1           |     pyhd8ed1ab_0          14 KB  conda-forge
    idna-3.10                  |     pyhd8ed1ab_0          49 KB  conda-forge
    multidict-6.1.0            |  py312h31fea79_1          55 KB  conda-forge
    propcache-0.2.0            |  py312h4389bb4_2          49 KB  conda-forge
    pycparser-2.22             |     pyhd8ed1ab_0         103 KB  conda-forge
    pysocks-1.7.1              |     pyh0701188_6          19 KB  conda-forge
    requests-2.32.3            |     pyhd8ed1ab_0          57 KB  conda-forge
    sniffio-1.3.1              |     pyhd8ed1ab_0          15 KB  conda-forge
    toolz-1.0.0                |     pyhd8ed1ab_0          51 KB  conda-forge
    typing-extensions-4.12.2   |       hd8ed1ab_0          10 KB  conda-forge
    typing_extensions-4.12.2   |     pyha770c72_0          39 KB  conda-forge
    urllib3-2.2.3              |     pyhd8ed1ab_0          96 KB  conda-forge
    win_inet_pton-1.1.0        |     pyh7428d3b_7           9 KB  conda-forge
    xarray-0.20.1              |     pyhd3eb1b0_1         563 KB
    yarl-1.16.0                |  py312h4389bb4_0         135 KB  conda-forge
    zstandard-0.23.0           |  py312h7606c53_1         313 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         3.8 MB

The following NEW packages will be INSTALLED:

  aiohappyeyeballs   conda-forge/noarch::aiohappyeyeballs-2.4.3-pyhd8ed1ab_0
  aiohttp            conda-forge/win-64::aiohttp-3.10.10-py312h31fea79_0
  aiosignal          conda-forge/noarch::aiosignal-1.3.1-pyhd8ed1ab_0
  anyio              conda-forge/noarch::anyio-4.6.2.post1-pyhd8ed1ab_0
  argopy             conda-forge/noarch::argopy-1.0.0-pyhd8ed1ab_0
  attrs              conda-forge/noarch::attrs-24.2.0-pyh71513ae_0
  brotli-python      conda-forge/win-64::brotli-python-1.1.0-py312h275cf98_2
  cffi               conda-forge/win-64::cffi-1.17.1-py312h4389bb4_0
  charset-normalizer conda-forge/noarch::charset-normalizer-3.4.0-pyhd8ed1ab_0
  erddapy            conda-forge/noarch::erddapy-2.2.3-pyhd8ed1ab_0
  exceptiongroup     conda-forge/noarch::exceptiongroup-1.2.2-pyhd8ed1ab_0
  frozenlist         conda-forge/win-64::frozenlist-1.5.0-py312h4389bb4_0
  fsspec             conda-forge/noarch::fsspec-2024.10.0-pyhff2d567_0
  h11                conda-forge/noarch::h11-0.14.0-pyhd8ed1ab_0
  h2                 conda-forge/noarch::h2-4.1.0-pyhd8ed1ab_0
  hpack              conda-forge/noarch::hpack-4.0.0-pyh9f0ad1d_0
  httpcore           conda-forge/noarch::httpcore-1.0.6-pyhd8ed1ab_0
  httpx              conda-forge/noarch::httpx-0.27.2-pyhd8ed1ab_0
  hyperframe         conda-forge/noarch::hyperframe-6.0.1-pyhd8ed1ab_0
  idna               conda-forge/noarch::idna-3.10-pyhd8ed1ab_0
  multidict          conda-forge/win-64::multidict-6.1.0-py312h31fea79_1
  propcache          conda-forge/win-64::propcache-0.2.0-py312h4389bb4_2
  pycparser          conda-forge/noarch::pycparser-2.22-pyhd8ed1ab_0
  pysocks            conda-forge/noarch::pysocks-1.7.1-pyh0701188_6
  requests           conda-forge/noarch::requests-2.32.3-pyhd8ed1ab_0
  sniffio            conda-forge/noarch::sniffio-1.3.1-pyhd8ed1ab_0
  toolz              conda-forge/noarch::toolz-1.0.0-pyhd8ed1ab_0
  typing-extensions  conda-forge/noarch::typing-extensions-4.12.2-hd8ed1ab_0
  typing_extensions  conda-forge/noarch::typing_extensions-4.12.2-pyha770c72_0
  urllib3            conda-forge/noarch::urllib3-2.2.3-pyhd8ed1ab_0
  win_inet_pton      conda-forge/noarch::win_inet_pton-1.1.0-pyh7428d3b_7
  xarray             pkgs/main/noarch::xarray-0.20.1-pyhd3eb1b0_1
  yarl               conda-forge/win-64::yarl-1.16.0-py312h4389bb4_0
  zstandard          conda-forge/win-64::zstandard-0.23.0-py312h7606c53_1

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi            pkgs/main/win-64::certifi-2024.8.30-p~ --> conda-forge/noarch::certifi-2024.8.30-pyhd8ed1ab_0


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
import argopy
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 1
----> 1 import argopy

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\argopy\__init__.py:25
     22 log.addHandler(logging.NullHandler())
     24 # Import facades:
---> 25 from .fetchers import ArgoDataFetcher as DataFetcher  # noqa: E402
     26 from .fetchers import ArgoIndexFetcher as IndexFetcher  # noqa: E402
     28 from .xarray import ArgoAccessor  # noqa: E402

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\argopy\fetchers.py:14
     12 import os
     13 import warnings
---> 14 import xarray as xr
     15 import pandas as pd
     16 import numpy as np

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\xarray\__init__.py:1
----> 1 from . import testing, tutorial, ufuncs
      2 from .backends.api import (
      3     load_dataarray,
      4     load_dataset,
   (...)
      8     save_mfdataset,
      9 )
     10 from .backends.rasterio_ import open_rasterio

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\xarray\testing.py:8
      4 from typing import Hashable, Set, Union
      6 import numpy as np
----> 8 from xarray.core import duck_array_ops, formatting, utils
      9 from xarray.core.dataarray import DataArray
     10 from xarray.core.dataset import Dataset

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\xarray\core\duck_array_ops.py:24
     21 from numpy import take, tensordot, transpose, unravel_index  # noqa
     22 from numpy import where as _where
---> 24 from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
     25 from .nputils import nanfirst, nanlast
     26 from .pycompat import (
     27     cupy_array_type,
     28     dask_array_type,
   (...)
     31     sparse_version,
     32 )

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\xarray\core\dask_array_ops.py:1
----> 1 from . import dtypes, nputils
      4 def dask_rolling_wrapper(moving_func, a, window, min_count=None, axis=-1):
      5     """Wrapper to apply bottleneck moving window funcs on dask arrays"""

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\xarray\core\dtypes.py:41
     31 NINF = AlwaysLessThan()
     34 # Pairs of types that, if both found, should be promoted to object dtype
     35 # instead of following NumPy's own type-promotion rules. These type promotion
     36 # rules match pandas instead. For reference, see the NumPy type hierarchy:
     37 # https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.scalars.html
     38 PROMOTE_TO_OBJECT = [
     39     {np.number, np.character},  # numpy promotes to character
     40     {np.bool_, np.character},  # numpy promotes to character
---> 41     {np.bytes_, np.unicode_},  # numpy promotes to unicode
     42 ]
     45 def maybe_promote(dtype):
     46     """Simpler equivalent of pandas.core.common._maybe_promote
     47
     48     Parameters
   (...)
     55     fill_value : Valid missing value for the promoted dtype.
     56     """

File ~\AppData\Local\anaconda3\envs\admt25\Lib\site-packages\numpy\__init__.py:400, in __getattr__(attr)
    397     raise AttributeError(__former_attrs__[attr], name=None)
    399 if attr in __expired_attributes__:
--> 400     raise AttributeError(
    401         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    402         f"{__expired_attributes__[attr]}",
    403         name=None
    404     )
    406 if attr == "chararray":
    407     warnings.warn(
    408         "`np.chararray` is deprecated and will be removed from "
    409         "the main namespace in the future. Use an array with a string "
    410         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.unicode_` was removed in the NumPy 2.0 release. Use `np.str_` instead.

conda install -c conda-forge xarray

Channels:
 - conda-forge
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\gordonc\AppData\Local\anaconda3\envs\admt25

  added / updated specs:
    - xarray


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    numpy-1.26.4               |  py312h8753938_0         6.2 MB  conda-forge
    xarray-2024.2.0            |     pyhd8ed1ab_0         724 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         6.9 MB

The following packages will be UPDATED:

  xarray              pkgs/main::xarray-0.20.1-pyhd3eb1b0_1 --> conda-forge::xarray-2024.2.0-pyhd8ed1ab_0

The following packages will be DOWNGRADED:

  numpy                               2.1.2-py312hf10105a_0 --> 1.26.4-py312h8753938_0


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
import argopy

Success!

Expected Output

Successful import, which was achieved.

Problem Description

Version specification in requirements.txt?

Versions

I only ran this after solving.

argopy.show_versions()
SYSTEM
------
commit: None
python: 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 15:47:54) [MSC v.1941 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: English_United States.1252
libhdf5: 1.14.4
libnetcdf: 4.9.2

INSTALLED VERSIONS: CORE
------------------------
aiohttp     : 3.10.10
argopy      : 1.0.0
decorator   : 5.1.1
erddapy     : 2.2.3
fsspec      : 2024.10.0
netCDF4     : 1.7.1
packaging   : 24.1
requests    : 2.32.3
scipy       : 1.14.1
toolz       : 1.0.0
xarray      : 2024.2.0

INSTALLED VERSIONS: EXT.UTIL
----------------------------
boto3       : -
gsw         : -
s3fs        : -
tqdm        : -
zarr        : -

INSTALLED VERSIONS: EXT.PERF
----------------------------
dask        : -
distributed : -
h5netcdf    : -
pyarrow     : 17.0.0

INSTALLED VERSIONS: EXT.PLOT
----------------------------
IPython     : 8.27.0
cartopy     : 0.24.0
ipykernel   : -
ipywidgets  : -
matplotlib  : 3.9.2
pyproj      : 3.7.0
seaborn     : 0.13.2

INSTALLED VERSIONS: DEV
-----------------------
aiofiles    : -
black       : -
bottleneck  : -
cfgrib      : -
cftime      : 1.6.4
codespell   : -
flake8      : -
numpy       : 1.26.4
pandas      : 2.2.3
pip         : 24.2
pytest      : -
pytest_cov  : -
pytest_env  : -
pytest_localftpserver: -
setuptools  : 75.1.0
sphinx      : -

INSTALLED VERSIONS: PIP
-----------------------
pytest-reportlog: -
@gmaze
Copy link
Member

gmaze commented Oct 25, 2024

Thanks @cgrdn for reporting this
Indeed we cannot work yet with numpy 2 because of #390 requiring to pin xarray to version older than 2024.3
as soon as this will be fixed, will be able to unconstraint and work with numpy 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants