Skip to content

Commit a05fe82

Browse files
authored
more engine environment tricks in preparation for numpy>=2 (#8978)
* 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`
1 parent 36a9cbc commit a05fe82

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

ci/install-upstream-wheels.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22

33
# install cython for building cftime without build isolation
4-
micromamba install "cython>=0.29.20" py-cpuinfo
4+
micromamba install "cython>=0.29.20" py-cpuinfo setuptools-scm
55
# temporarily (?) remove numbagg and numba
66
micromamba remove -y numba numbagg sparse
77
# temporarily remove numexpr
88
micromamba remove -y numexpr
99
# temporarily remove backends
10-
micromamba remove -y cf_units hdf5 h5py netcdf4
10+
micromamba remove -y cf_units hdf5 h5py netcdf4 pydap
1111
# forcibly remove packages to avoid artifacts
1212
micromamba remove -y --force \
1313
numpy \
@@ -31,7 +31,8 @@ python -m pip install \
3131
numpy \
3232
scipy \
3333
matplotlib \
34-
pandas
34+
pandas \
35+
h5py
3536
# for some reason pandas depends on pyarrow already.
3637
# Remove once a `pyarrow` version compiled with `numpy>=2.0` is on `conda-forge`
3738
python -m pip install \
@@ -70,6 +71,6 @@ python -m pip install \
7071
git+https://github.com/intake/filesystem_spec \
7172
git+https://github.com/SciTools/nc-time-axis \
7273
git+https://github.com/xarray-contrib/flox \
74+
git+https://github.com/h5netcdf/h5netcdf \
7375
git+https://github.com/dgasmith/opt_einsum
7476
# git+https://github.com/pydata/sparse
75-
# git+https://github.com/h5netcdf/h5netcdf

xarray/tests/__init__.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,36 @@ def _importorskip(
142142
not has_scipy_or_netCDF4, reason="requires scipy or netCDF4"
143143
)
144144
has_numpy_array_api, requires_numpy_array_api = _importorskip("numpy", "1.26.0")
145-
has_h5netcdf_ros3, requires_h5netcdf_ros3 = _importorskip("h5netcdf", "1.3.0")
146145

146+
147+
def _importorskip_h5netcdf_ros3():
148+
try:
149+
import h5netcdf
150+
151+
has_h5netcdf = True
152+
except ImportError:
153+
has_h5netcdf = False
154+
155+
if not has_h5netcdf:
156+
return has_h5netcdf, pytest.mark.skipif(
157+
not has_h5netcdf, reason="requires h5netcdf"
158+
)
159+
160+
h5netcdf_with_ros3 = Version(h5netcdf.__version__) >= Version("1.3.0")
161+
162+
import h5py
163+
164+
h5py_with_ros3 = h5py.get_config().ros3
165+
166+
has_h5netcdf_ros3 = h5netcdf_with_ros3 and h5py_with_ros3
167+
168+
return has_h5netcdf_ros3, pytest.mark.skipif(
169+
not has_h5netcdf_ros3,
170+
reason="requires h5netcdf>=1.3.0 and h5py with ros3 support",
171+
)
172+
173+
174+
has_h5netcdf_ros3, requires_h5netcdf_ros3 = _importorskip_h5netcdf_ros3()
147175
has_netCDF4_1_6_2_or_above, requires_netCDF4_1_6_2_or_above = _importorskip(
148176
"netCDF4", "1.6.2"
149177
)

xarray/tests/test_formatting.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pandas as pd
88
import pytest
9-
from numpy.core import defchararray
109

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

0 commit comments

Comments
 (0)