Skip to content

Commit

Permalink
more engine environment tricks in preparation for numpy>=2 (#8978)
Browse files Browse the repository at this point in the history
* build-deps for numcodecs

* temporarily remove `pydap` from the upstream-dev CI

* try adding back `h5netcdf`

* skip h5netcdf ros3 tests if h5py was compiled without support for ros3

* invert the condition

* also invert the other condition

* replace `numpy.core.defchararray.add` with `numpy.strings.add`

* use `numpy.char.add` instead

`numpy.strings` exists since `numpy>=2`
  • Loading branch information
keewis authored Apr 29, 2024
1 parent 36a9cbc commit a05fe82
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
9 changes: 5 additions & 4 deletions ci/install-upstream-wheels.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash

# install cython for building cftime without build isolation
micromamba install "cython>=0.29.20" py-cpuinfo
micromamba install "cython>=0.29.20" py-cpuinfo setuptools-scm
# temporarily (?) remove numbagg and numba
micromamba remove -y numba numbagg sparse
# temporarily remove numexpr
micromamba remove -y numexpr
# temporarily remove backends
micromamba remove -y cf_units hdf5 h5py netcdf4
micromamba remove -y cf_units hdf5 h5py netcdf4 pydap
# forcibly remove packages to avoid artifacts
micromamba remove -y --force \
numpy \
Expand All @@ -31,7 +31,8 @@ python -m pip install \
numpy \
scipy \
matplotlib \
pandas
pandas \
h5py
# for some reason pandas depends on pyarrow already.
# Remove once a `pyarrow` version compiled with `numpy>=2.0` is on `conda-forge`
python -m pip install \
Expand Down Expand Up @@ -70,6 +71,6 @@ python -m pip install \
git+https://github.com/intake/filesystem_spec \
git+https://github.com/SciTools/nc-time-axis \
git+https://github.com/xarray-contrib/flox \
git+https://github.com/h5netcdf/h5netcdf \
git+https://github.com/dgasmith/opt_einsum
# git+https://github.com/pydata/sparse
# git+https://github.com/h5netcdf/h5netcdf
30 changes: 29 additions & 1 deletion xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,36 @@ def _importorskip(
not has_scipy_or_netCDF4, reason="requires scipy or netCDF4"
)
has_numpy_array_api, requires_numpy_array_api = _importorskip("numpy", "1.26.0")
has_h5netcdf_ros3, requires_h5netcdf_ros3 = _importorskip("h5netcdf", "1.3.0")


def _importorskip_h5netcdf_ros3():
try:
import h5netcdf

has_h5netcdf = True
except ImportError:
has_h5netcdf = False

if not has_h5netcdf:
return has_h5netcdf, pytest.mark.skipif(
not has_h5netcdf, reason="requires h5netcdf"
)

h5netcdf_with_ros3 = Version(h5netcdf.__version__) >= Version("1.3.0")

import h5py

h5py_with_ros3 = h5py.get_config().ros3

has_h5netcdf_ros3 = h5netcdf_with_ros3 and h5py_with_ros3

return has_h5netcdf_ros3, pytest.mark.skipif(
not has_h5netcdf_ros3,
reason="requires h5netcdf>=1.3.0 and h5py with ros3 support",
)


has_h5netcdf_ros3, requires_h5netcdf_ros3 = _importorskip_h5netcdf_ros3()
has_netCDF4_1_6_2_or_above, requires_netCDF4_1_6_2_or_above = _importorskip(
"netCDF4", "1.6.2"
)
Expand Down
7 changes: 3 additions & 4 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pandas as pd
import pytest
from numpy.core import defchararray

import xarray as xr
from xarray.core import formatting
Expand Down Expand Up @@ -770,9 +769,9 @@ def test_repr_file_collapsed(tmp_path) -> None:
)
def test__mapping_repr(display_max_rows, n_vars, n_attr) -> None:
long_name = "long_name"
a = defchararray.add(long_name, np.arange(0, n_vars).astype(str))
b = defchararray.add("attr_", np.arange(0, n_attr).astype(str))
c = defchararray.add("coord", np.arange(0, n_vars).astype(str))
a = np.char.add(long_name, np.arange(0, n_vars).astype(str))
b = np.char.add("attr_", np.arange(0, n_attr).astype(str))
c = np.char.add("coord", np.arange(0, n_vars).astype(str))
attrs = {k: 2 for k in b}
coords = {_c: np.array([0, 1], dtype=np.uint64) for _c in c}
data_vars = dict()
Expand Down

0 comments on commit a05fe82

Please sign in to comment.