Skip to content

Commit 3ed5107

Browse files
authored
Drop NumPy 1.x and refuse it at import time (#3754)
install_requires now says numpy >=2.0, and xrspatial/__init__.py imports a one-function module first that raises ImportError: xarray-spatial requires NumPy 2.0 or newer, found 1.26.4 before any submodule loads. The min-deps job went red on 2026-10-10 when pyarrow 26.0.0 shipped: it needs numpy 2 but declares no numpy requirement, so pip installed it beside the pinned numpy 1.26.0 and the failure surfaced as an AttributeError in zonal three frames from the cause (#3751). numba's own numpy check has the same shape. The other floors move to their first numpy-2-capable releases so the min-deps job can still install the set it declares: numba 0.60, scipy 1.13, pandas 2.2.2. The setup.cfg derivation comments and the min-deps pins follow. Closes #3751.
1 parent 71e3ec1 commit 3ed5107

6 files changed

Lines changed: 88 additions & 12 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ jobs:
9393
run: |
9494
python -m pip install --upgrade pip
9595
pip install -e .[tests] \
96-
numba==0.59.0 scipy==1.11.2 xarray==2025.11.0 \
97-
numpy==1.26.0 pandas==2.2.0 urllib3==2.7.0 zstandard==0.22.0
96+
numba==0.60.0 scipy==1.13.0 xarray==2025.11.0 \
97+
numpy==2.0.0 pandas==2.2.2 urllib3==2.7.0 zstandard==0.22.0
9898
- name: Run pytest (fast lane)
9999
run: pytest -m "not slow"
100100

‎setup.cfg‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ include_package_data = True
2222
# .github/workflows/test.yml, which installs exactly these versions and
2323
# runs the suite against them. Issue #3701 has the full derivation.
2424
#
25-
# numba, scipy oldest release shipping a CPython 3.12 wheel, which
26-
# is the floor python_requires allows anyway
27-
# numpy >=1.26 first cp312 wheel, and xarray's own numpy floor
25+
# numpy >=2.0 NumPy 1.x is not supported. xrspatial/__init__.py
26+
# re-checks this at import and raises ImportError,
27+
# because pyarrow (tests extra) declares no numpy
28+
# requirement pip could act on and numba's own check
29+
# fires deep inside a submodule import.
30+
# numba >=0.60 first release that accepts numpy 2 (0.59 declares
31+
# numpy<1.27)
32+
# scipy >=1.13 first release built against numpy 2 (1.11 and
33+
# 1.12 declare numpy<1.28)
2834
# numpy <2.5 mirrors numba: 0.64-0.66 declare numpy<2.5 and numba
2935
# re-checks it at import in _ensure_critical_deps.
3036
# Without this, pip installs a numpy that makes
@@ -35,17 +41,19 @@ include_package_data = True
3541
# ops, so morph_gradient / morph_white_tophat /
3642
# morph_black_tophat and the mcda and corridor
3743
# metadata tests lose res and crs
38-
# pandas >=2.2 required by xarray >=2025.11; pandas is a direct
39-
# import here (zonal, dasymetric, focal) and part of
40-
# the public API -- zonal_stats returns a DataFrame
44+
# pandas >=2.2.2 first 2.2.x without the numpy<2 cap (2.2.0 and
45+
# 2.2.1 declare it); xarray >=2025.11 needs >=2.2
46+
# anyway. pandas is a direct import here (zonal,
47+
# dasymetric, focal) and part of the public API --
48+
# zonal_stats returns a DataFrame
4149
# urllib3 >=2.7 first release with no open advisory against the
4250
# streaming read path used by the COG-over-HTTP source
4351
install_requires =
44-
numba >=0.59
45-
scipy >=1.11.2
52+
numba >=0.60
53+
scipy >=1.13
4654
xarray >=2025.11
47-
numpy >=1.26,<2.5
48-
pandas >=2.2
55+
numpy >=2.0,<2.5
56+
pandas >=2.2.2
4957
urllib3 >=2.7
5058
packages = find:
5159
python_requires = >=3.12

‎xrspatial/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from xrspatial._numpy_floor import _check_numpy_version # noqa: F401
12
from xrspatial.aspect import aspect # noqa
23
from xrspatial.aspect import eastness # noqa
34
from xrspatial.aspect import northness # noqa

‎xrspatial/_numpy_floor.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Import-time NumPy floor. Imported first by xrspatial/__init__.py.
2+
3+
numba and pyarrow both reject numpy 1.x in their own ways (numba at
4+
import, pyarrow 26 at import with no metadata pin that pip could act
5+
on), which surfaces deep inside a submodule import as an unrelated
6+
error. Checking here, before any submodule loads, turns that into one
7+
plain sentence that names the version found.
8+
"""
9+
import numpy as _np
10+
11+
12+
def _check_numpy_version(version):
13+
"""Raise ImportError if ``version`` is a NumPy 1.x release string."""
14+
try:
15+
major = int(version.split(".")[0])
16+
except ValueError:
17+
return
18+
if major < 2:
19+
raise ImportError(
20+
f"xarray-spatial requires NumPy 2.0 or newer, found {version}. "
21+
"Upgrade with: pip install 'numpy>=2'"
22+
)
23+
24+
25+
_check_numpy_version(_np.__version__)

‎xrspatial/tests/test_dependency_metadata_3701.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ def test_every_required_dependency_has_a_lower_bound():
7373
f"{name} is declared without a lower bound"
7474

7575

76+
def test_numpy_floor_is_two():
77+
"""NumPy 1.x is not supported; the floor and the import-time check agree.
78+
79+
xrspatial/__init__.py raises ImportError on numpy < 2. The metadata
80+
has to say the same thing or pip will happily install a combination
81+
the package then refuses to import.
82+
"""
83+
spec = _install_requires()["numpy"]
84+
assert not spec.contains("1.26.4"), "setup.cfg still admits numpy 1.x"
85+
assert spec.contains("2.0.0")
86+
87+
7688
def test_numpy_has_an_upper_bound():
7789
"""numba caps numpy and re-checks the cap at import time.
7890
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""The import-time NumPy floor check in xrspatial/__init__.py.
2+
3+
NumPy 1.x is not supported. Nothing in the dependency metadata stops a
4+
user from ending up with numpy 1.26 next to a numba or pyarrow build
5+
that rejects it (pyarrow 26 declares no numpy requirement at all and
6+
raises at import), so the package checks once, up front, and says
7+
plainly what it found.
8+
"""
9+
import pytest
10+
11+
from xrspatial import _check_numpy_version
12+
13+
14+
@pytest.mark.parametrize("version", ["1.26.0", "1.26.4", "1.26.0.dev0+abc", "1.99.9"])
15+
def test_numpy_1x_is_rejected(version):
16+
with pytest.raises(ImportError) as excinfo:
17+
_check_numpy_version(version)
18+
msg = str(excinfo.value)
19+
assert "NumPy 2.0 or newer" in msg
20+
assert version in msg
21+
22+
23+
@pytest.mark.parametrize("version", ["2.0.0", "2.0.2", "2.5.4", "2.6.0.dev0+git", "3.0.0"])
24+
def test_numpy_2_and_later_pass(version):
25+
_check_numpy_version(version)
26+
27+
28+
def test_installed_numpy_passes_the_check():
29+
import numpy
30+
_check_numpy_version(numpy.__version__)

0 commit comments

Comments
 (0)