Skip to content

Commit 96f491a

Browse files
committed
Drop support for numpy < 1.24
1 parent ed95105 commit 96f491a

10 files changed

Lines changed: 38 additions & 167 deletions

File tree

‎astropy/units/quantity_helper/function_helpers.py‎

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from astropy.units.errors import UnitConversionError, UnitsError, UnitTypeError
4545
from astropy.utils.compat import (
4646
COPY_IF_NEEDED,
47-
NUMPY_LT_1_24,
4847
NUMPY_LT_2_0,
4948
NUMPY_LT_2_1,
5049
NUMPY_LT_2_2,
@@ -1079,51 +1078,6 @@ def histogramdd(sample, bins=10, range=None, density=None, weights=None):
10791078
)
10801079

10811080

1082-
if NUMPY_LT_1_24:
1083-
1084-
@function_helper(helps={np.histogram})
1085-
def histogram_pre_1_24(
1086-
a, bins=10, range=None, normed=None, weights=None, density=None
1087-
):
1088-
args, kwargs, unit, out = histogram(
1089-
a, bins=bins, range=range, weights=weights, density=density or normed
1090-
)
1091-
kwargs["normed"] = normed
1092-
kwargs["density"] = density
1093-
return args, kwargs, unit, out
1094-
1095-
@function_helper(helps={np.histogram2d})
1096-
def histogram2d_pre_1_24(
1097-
x, y, bins=10, range=None, normed=None, weights=None, density=None
1098-
):
1099-
args, kwargs, unit, out = histogram2d(
1100-
x,
1101-
y,
1102-
bins=bins,
1103-
range=range,
1104-
weights=weights,
1105-
density=density or normed,
1106-
)
1107-
kwargs["normed"] = normed
1108-
kwargs["density"] = density
1109-
return args, kwargs, unit, out
1110-
1111-
@function_helper(helps={np.histogramdd})
1112-
def histogramdd_pre_1_24(
1113-
sample, bins=10, range=None, normed=None, weights=None, density=None
1114-
):
1115-
args, kwargs, unit, out = histogramdd(
1116-
sample,
1117-
bins=bins,
1118-
range=range,
1119-
weights=weights,
1120-
density=density or normed,
1121-
)
1122-
kwargs["normed"] = normed
1123-
kwargs["density"] = density
1124-
return args, kwargs, unit, out
1125-
1126-
11271081
@function_helper
11281082
def diff(a, n=1, axis=-1, prepend=np._NoValue, append=np._NoValue):
11291083
a = _as_quantity(a)
@@ -1204,9 +1158,11 @@ def unique(
12041158
return_inverse=False,
12051159
return_counts=False,
12061160
axis=None,
1161+
*,
1162+
equal_nan=True,
12071163
**kwargs,
12081164
):
1209-
# having **kwargs allows to support equal_nan (for not NUMPY_LT_1_24) without
1165+
# having **kwargs allows to support sorted (for not NUMPY_LT_2_3) without
12101166
# introducing it pre-maturely in older supported numpy versions
12111167
unit = ar.unit
12121168
n_index = sum(bool(i) for i in (return_index, return_inverse, return_counts))
@@ -1215,7 +1171,7 @@ def unique(
12151171

12161172
return (
12171173
(ar.value, return_index, return_inverse, return_counts, axis),
1218-
kwargs,
1174+
kwargs | {"equal_nan": equal_nan},
12191175
unit,
12201176
None,
12211177
)

‎astropy/units/structured.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import numpy as np
1414

15-
from astropy.utils.compat.numpycompat import NUMPY_LT_1_24
16-
1715
from .core import UNITY, Unit, UnitBase
1816

1917
if TYPE_CHECKING:
@@ -246,11 +244,7 @@ def _recursively_apply(self, func, cls=None):
246244
If given, should be a subclass of `~numpy.void`. By default,
247245
will return a new `~astropy.units.StructuredUnit` instance.
248246
"""
249-
applied = tuple(func(part) for part in self.values())
250-
if NUMPY_LT_1_24:
251-
results = np.array(applied, self._units.dtype)[()]
252-
else:
253-
results = np.void(applied, self._units.dtype)
247+
results = np.void(tuple(map(func, self.values())), self._units.dtype)
254248
if cls is not None:
255249
return results.view((cls, results.dtype))
256250

‎astropy/units/tests/test_quantity_non_ufuncs.py‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
TBD_FUNCTIONS,
2424
UNSUPPORTED_FUNCTIONS,
2525
)
26-
from astropy.utils.compat import (
27-
NUMPY_LT_1_24,
28-
NUMPY_LT_1_25,
29-
NUMPY_LT_2_0,
30-
NUMPY_LT_2_1,
31-
NUMPY_LT_2_2,
32-
)
26+
from astropy.utils.compat import NUMPY_LT_1_25, NUMPY_LT_2_0, NUMPY_LT_2_1, NUMPY_LT_2_2
3327

3428
if TYPE_CHECKING:
3529
from types import FunctionType, ModuleType
@@ -2036,9 +2030,10 @@ def test_sort(self):
20362030
def test_sort_axis(self):
20372031
self.check(np.sort, axis=0)
20382032

2039-
@pytest.mark.skipif(not NUMPY_LT_1_24, reason="np.msort is deprecated")
2033+
@pytest.mark.skipif(not NUMPY_LT_2_0, reason="np.msort was removed in numpy 2.0")
20402034
def test_msort(self):
2041-
self.check(np.msort)
2035+
with pytest.warns(DeprecationWarning):
2036+
self.check(np.msort)
20422037

20432038
@needs_array_function
20442039
def test_sort_complex(self):

‎astropy/utils/compat/numpycompat.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
__all__ = [
1212
"COPY_IF_NEEDED",
13-
"NUMPY_LT_1_24",
1413
"NUMPY_LT_1_25",
1514
"NUMPY_LT_1_26",
1615
"NUMPY_LT_2_0",
@@ -22,7 +21,6 @@
2221
# TODO: It might also be nice to have aliases to these named for specific
2322
# features/bugs we're checking for (ex:
2423
# astropy.table.table._BROKEN_UNICODE_TABLE_SORT)
25-
NUMPY_LT_1_24 = not minversion(np, "1.24")
2624
NUMPY_LT_1_25 = not minversion(np, "1.25")
2725
NUMPY_LT_1_26 = not minversion(np, "1.26")
2826
NUMPY_LT_2_0 = not minversion(np, "2.0")

‎astropy/utils/masked/function_helpers.py‎

Lines changed: 23 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616

1717
from astropy.units.quantity_helper.function_helpers import FunctionAssigner
18-
from astropy.utils.compat import NUMPY_LT_1_24, NUMPY_LT_2_0, NUMPY_LT_2_1, NUMPY_LT_2_2
18+
from astropy.utils.compat import NUMPY_LT_2_0, NUMPY_LT_2_1, NUMPY_LT_2_2
1919

2020
if NUMPY_LT_2_0:
2121
import numpy.core as np_core
@@ -571,11 +571,9 @@ def bincount(x, weights=None, minlength=0):
571571

572572
@dispatched_function
573573
def msort(a):
574-
if not NUMPY_LT_1_24:
575-
warnings.warn(
576-
"msort is deprecated, use np.sort(a, axis=0) instead",
577-
DeprecationWarning,
578-
)
574+
warnings.warn(
575+
"msort is deprecated, use np.sort(a, axis=0) instead", DeprecationWarning
576+
)
579577
result = a.copy()
580578
result.sort(axis=0)
581579
return result, None, None
@@ -749,27 +747,14 @@ def median(a, axis=None, out=None, overwrite_input=False, keepdims=False):
749747
if out is not None and not isinstance(out, Masked):
750748
raise NotImplementedError
751749

752-
a = Masked(a)
753-
754-
if NUMPY_LT_1_24:
755-
r, k = _ureduce(
756-
a,
757-
func=_masked_median,
758-
axis=axis,
759-
out=out,
760-
overwrite_input=overwrite_input,
761-
)
762-
result = (r.reshape(k) if keepdims else r) if out is None else out
763-
764-
else:
765-
result = _ureduce(
766-
a,
767-
func=_masked_median,
768-
axis=axis,
769-
out=out,
770-
overwrite_input=overwrite_input,
771-
keepdims=keepdims,
772-
)
750+
result = _ureduce(
751+
Masked(a),
752+
func=_masked_median,
753+
axis=axis,
754+
out=out,
755+
overwrite_input=overwrite_input,
756+
keepdims=keepdims,
757+
)
773758
return result, None, None
774759

775760

@@ -832,36 +817,7 @@ def _preprocess_quantile(a, q, axis=None, out=None, **kwargs):
832817
return a, q, axis, out, kwargs
833818

834819

835-
if NUMPY_LT_1_24:
836-
837-
@dispatched_function
838-
def quantile(
839-
a,
840-
q,
841-
axis=None,
842-
out=None,
843-
overwrite_input=False,
844-
method="linear",
845-
keepdims=False,
846-
*,
847-
interpolation=None,
848-
):
849-
a, q, axis, out, kwargs = _preprocess_quantile(
850-
a,
851-
q,
852-
axis,
853-
out,
854-
overwrite_input=overwrite_input,
855-
method=method,
856-
keepdims=keepdims,
857-
interpolation=interpolation,
858-
)
859-
keepdims = kwargs.pop("keepdims", False)
860-
r, k = _ureduce(a, func=_masked_quantile, q=q, axis=axis, out=out, **kwargs)
861-
result = (r.reshape(q.shape + k) if keepdims else r) if out is None else out
862-
return result, None, None
863-
864-
elif NUMPY_LT_2_0:
820+
if NUMPY_LT_2_0:
865821

866822
@dispatched_function
867823
def quantile(
@@ -1446,33 +1402,18 @@ def _copy_of_mask(a):
14461402
return mask.copy() if mask is not None else False
14471403

14481404

1449-
if NUMPY_LT_1_24: # "kind" argument introduced in 1.24.
1450-
1451-
@dispatched_function
1452-
def in1d(ar1, ar2, assume_unique=False, invert=False):
1453-
mask = _copy_of_mask(ar1).ravel()
1454-
return _in1d(ar1, ar2, assume_unique, invert), mask, None
1455-
1456-
@dispatched_function
1457-
def isin(element, test_elements, assume_unique=False, invert=False):
1458-
element = np.asanyarray(element)
1459-
result = _in1d(element, test_elements, assume_unique, invert)
1460-
result.shape = element.shape
1461-
return result, _copy_of_mask(element), None
1462-
1463-
else:
1405+
@dispatched_function
1406+
def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
1407+
mask = _copy_of_mask(ar1).ravel()
1408+
return _in1d(ar1, ar2, assume_unique, invert, kind=kind), mask, None
14641409

1465-
@dispatched_function
1466-
def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
1467-
mask = _copy_of_mask(ar1).ravel()
1468-
return _in1d(ar1, ar2, assume_unique, invert, kind=kind), mask, None
14691410

1470-
@dispatched_function
1471-
def isin(element, test_elements, assume_unique=False, invert=False, *, kind=None):
1472-
element = np.asanyarray(element)
1473-
result = _in1d(element, test_elements, assume_unique, invert, kind=kind)
1474-
result.shape = element.shape
1475-
return result, _copy_of_mask(element), None
1411+
@dispatched_function
1412+
def isin(element, test_elements, assume_unique=False, invert=False, *, kind=None):
1413+
element = np.asanyarray(element)
1414+
result = _in1d(element, test_elements, assume_unique, invert, kind=kind)
1415+
result.shape = element.shape
1416+
return result, _copy_of_mask(element), None
14761417

14771418

14781419
@dispatched_function

‎astropy/utils/masked/tests/test_function_helpers.py‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
"""
1313

14-
import contextlib
1514
import itertools
1615

1716
import numpy as np
@@ -24,13 +23,7 @@
2423
get_covered_functions,
2524
get_wrapped_functions,
2625
)
27-
from astropy.utils.compat import (
28-
NUMPY_LT_1_24,
29-
NUMPY_LT_1_25,
30-
NUMPY_LT_2_0,
31-
NUMPY_LT_2_1,
32-
NUMPY_LT_2_2,
33-
)
26+
from astropy.utils.compat import NUMPY_LT_1_25, NUMPY_LT_2_0, NUMPY_LT_2_1, NUMPY_LT_2_2
3427
from astropy.utils.masked import Masked, MaskedNDArray
3528
from astropy.utils.masked.function_helpers import (
3629
APPLY_TO_BOTH_FUNCTIONS,
@@ -1272,11 +1265,7 @@ def test_sort_complex(self):
12721265

12731266
@pytest.mark.skipif(not NUMPY_LT_2_0, reason="np.msort was removed in numpy 2.0")
12741267
def test_msort(self):
1275-
with (
1276-
contextlib.nullcontext()
1277-
if NUMPY_LT_1_24
1278-
else pytest.warns(DeprecationWarning, match="msort is deprecated")
1279-
):
1268+
with pytest.warns(DeprecationWarning, match="msort is deprecated"):
12801269
o = np.msort(self.ma)
12811270
expected = np.sort(self.ma, axis=0)
12821271
assert_masked_equal(o, expected)
@@ -1708,7 +1697,6 @@ def test_in1d(self):
17081697
assert_masked_equal(np.in1d(Masked([]), []), Masked([])) # noqa: NPY201
17091698
assert_masked_equal(np.in1d(Masked([]), [], invert=True), Masked([])) # noqa: NPY201
17101699

1711-
@pytest.mark.skipif(NUMPY_LT_1_24, reason="kind introduced in numpy 1.24")
17121700
def test_in1d_kind_table_error(self):
17131701
with pytest.raises(ValueError, match="'table' method is not supported"):
17141702
np.in1d(Masked([1, 2, 3]), [4, 5], kind="table") # noqa: NPY201

‎docs/changes/18160.other.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The minimum required NumPy version is now 1.24.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ keywords = [
4242
"ascii",
4343
]
4444
dependencies = [
45-
"numpy>=1.23.2",
45+
"numpy>=1.24",
4646
"pyerfa>=2.0.1.1",
4747
"astropy-iers-data>=0.2025.4.28.0.37.27",
4848
"PyYAML>=6.0.0",

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Specify the minimum version for the Numpy C-API
1414
for ext in ext_modules:
1515
if ext.include_dirs and "numpy" in ext.include_dirs[0]:
16-
ext.define_macros.append(("NPY_TARGET_VERSION", "NPY_1_23_API_VERSION"))
16+
ext.define_macros.append(("NPY_TARGET_VERSION", "NPY_1_24_API_VERSION"))
1717
ext.define_macros.append(("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"))
1818

1919
setup(ext_modules=ext_modules)

‎tox.ini‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
py{311,312,313,dev}-test{,-recdeps,-alldeps,-oldestdeps,-devdeps,-devinfra,-predeps,-numpy123,-numpy124,-numpy125,-mpl380}{,-cov}{,-clocale}{,-fitsio}{,-noscipy}
3+
py{311,312,313,dev}-test{,-recdeps,-alldeps,-oldestdeps,-devdeps,-devinfra,-predeps,-numpy124,-numpy125,-mpl380}{,-cov}{,-clocale}{,-fitsio}{,-noscipy}
44
# Only these two exact tox environments have corresponding figure hash files.
55
py311-test-image-mpl380-cov
66
py311-test-image-mpldev-cov
@@ -50,7 +50,6 @@ description =
5050
devinfra: like devdeps but also dev version of infrastructure
5151
oldestdeps: with the oldest supported version of direct dependencies
5252
cov: and test coverage
53-
numpy123: with numpy 1.23.*
5453
numpy124: with numpy 1.24.*
5554
numpy125: with numpy 1.25.*
5655
image: with image tests
@@ -60,7 +59,6 @@ description =
6059
noscipy: without scipy-dev
6160

6261
deps =
63-
numpy123: numpy==1.23.*
6462
numpy124: numpy==1.24.*
6563
numpy125: numpy==1.25.*
6664

0 commit comments

Comments
 (0)