Skip to content

Commit 30f297b

Browse files
authored
Merge pull request #28615 from mtsokol/upgrade-array-api
ENH: Upgrade Array API version to 2024.12
2 parents ff0dd30 + ff92ba8 commit 30f297b

File tree

12 files changed

+64
-22
lines changed

12 files changed

+64
-22
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ jobs:
324324
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
325325
with:
326326
repository: data-apis/array-api-tests
327-
ref: '827edd804bcace9d64176b8115138d29ae3e8dec' # Latest commit as of 2024-07-30
327+
ref: 'c48410f96fc58e02eea844e6b7f6cc01680f77ce' # Latest commit as of 2025-04-01
328328
submodules: 'true'
329329
path: 'array-api-tests'
330330
persist-credentials: false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* NumPy's ``__array_api_version__`` was upgraded from ``2023.12`` to ``2024.12``.
2+
* `numpy.count_nonzero` for ``axis=None`` (default) now returns a NumPy scalar
3+
instead of a Python integer.
4+
* The parameter ``axis`` in `numpy.take_along_axis` function has now a default
5+
value of ``-1``.

numpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
# import with `from numpy import *`.
290290
__future_scalars__ = {"str", "bytes", "object"}
291291

292-
__array_api_version__ = "2023.12"
292+
__array_api_version__ = "2024.12"
293293

294294
from ._array_api_info import __array_namespace_info__
295295

numpy/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ _DTypeNum: TypeAlias = L[
965965
]
966966
_DTypeBuiltinKind: TypeAlias = L[0, 1, 2]
967967

968-
_ArrayAPIVersion: TypeAlias = L["2021.12", "2022.12", "2023.12"]
968+
_ArrayAPIVersion: TypeAlias = L["2021.12", "2022.12", "2023.12", "2024.12"]
969969

970970
_CastingKind: TypeAlias = L["no", "equiv", "safe", "same_kind", "unsafe"]
971971

@@ -1153,7 +1153,7 @@ __NUMPY_SETUP__: Final[L[False]] = False
11531153
__numpy_submodules__: Final[set[LiteralString]] = ...
11541154
__former_attrs__: Final[_FormerAttrsDict] = ...
11551155
__future_scalars__: Final[set[L["bytes", "str", "object"]]] = ...
1156-
__array_api_version__: Final[L["2023.12"]] = "2023.12"
1156+
__array_api_version__: Final[L["2024.12"]] = "2024.12"
11571157
test: Final[PytestTester] = ...
11581158

11591159
@type_check_only

numpy/_core/numeric.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def full_like(
416416

417417
#
418418
@overload
419-
def count_nonzero(a: ArrayLike, axis: None = None, *, keepdims: L[False] = False) -> int: ...
419+
def count_nonzero(a: ArrayLike, axis: None = None, *, keepdims: L[False] = False) -> np.intp: ...
420420
@overload
421421
def count_nonzero(a: _ScalarLike_co, axis: _ShapeLike | None = None, *, keepdims: L[True]) -> np.intp: ...
422422
@overload

numpy/_core/src/multiarray/array_api_standard.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ array_array_namespace(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds
6060
return NULL;
6161
} else if (PyUnicode_CompareWithASCIIString(array_api_version, "2021.12") != 0 &&
6262
PyUnicode_CompareWithASCIIString(array_api_version, "2022.12") != 0 &&
63-
PyUnicode_CompareWithASCIIString(array_api_version, "2023.12") != 0)
63+
PyUnicode_CompareWithASCIIString(array_api_version, "2023.12") != 0 &&
64+
PyUnicode_CompareWithASCIIString(array_api_version, "2024.12") != 0)
6465
{
6566
PyErr_Format(PyExc_ValueError,
6667
"Version \"%U\" of the Array API Standard is not supported.",

numpy/_core/src/multiarray/multiarraymodule.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,14 +2280,18 @@ array_count_nonzero(PyObject *NPY_UNUSED(self), PyObject *const *args, Py_ssize_
22802280
return NULL;
22812281
}
22822282

2283-
count = PyArray_CountNonzero(array);
2284-
2283+
count = PyArray_CountNonzero(array);
22852284
Py_DECREF(array);
22862285

22872286
if (count == -1) {
22882287
return NULL;
22892288
}
2290-
return PyLong_FromSsize_t(count);
2289+
2290+
PyArray_Descr *descr = PyArray_DescrFromType(NPY_INTP);
2291+
if (descr == NULL) {
2292+
return NULL;
2293+
}
2294+
return PyArray_Scalar(&count, descr, NULL);
22912295
}
22922296

22932297
static PyObject *

numpy/_core/tests/test_regression.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,21 +2570,23 @@ def test__array_namespace__(self):
25702570
assert xp is np
25712571
xp = arr.__array_namespace__(api_version="2023.12")
25722572
assert xp is np
2573+
xp = arr.__array_namespace__(api_version="2024.12")
2574+
assert xp is np
25732575
xp = arr.__array_namespace__(api_version=None)
25742576
assert xp is np
25752577

25762578
with pytest.raises(
25772579
ValueError,
2578-
match="Version \"2024.12\" of the Array API Standard "
2580+
match="Version \"2025.12\" of the Array API Standard "
25792581
"is not supported."
25802582
):
2581-
arr.__array_namespace__(api_version="2024.12")
2583+
arr.__array_namespace__(api_version="2025.12")
25822584

25832585
with pytest.raises(
25842586
ValueError,
25852587
match="Only None and strings are allowed as the Array API version"
25862588
):
2587-
arr.__array_namespace__(api_version=2023)
2589+
arr.__array_namespace__(api_version=2024)
25882590

25892591
def test_isin_refcnt_bug(self):
25902592
# gh-25295

numpy/lib/_shape_base_impl.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def _make_along_axis_idx(arr_shape, indices, axis):
5050
return tuple(fancy_index)
5151

5252

53-
def _take_along_axis_dispatcher(arr, indices, axis):
53+
def _take_along_axis_dispatcher(arr, indices, axis=None):
5454
return (arr, indices)
5555

5656

5757
@array_function_dispatch(_take_along_axis_dispatcher)
58-
def take_along_axis(arr, indices, axis):
58+
def take_along_axis(arr, indices, axis=-1):
5959
"""
6060
Take values from the input array by matching 1d index and data slices.
6161
@@ -71,14 +71,17 @@ def take_along_axis(arr, indices, axis):
7171
arr : ndarray (Ni..., M, Nk...)
7272
Source array
7373
indices : ndarray (Ni..., J, Nk...)
74-
Indices to take along each 1d slice of `arr`. This must match the
75-
dimension of arr, but dimensions Ni and Nj only need to broadcast
76-
against `arr`.
77-
axis : int
74+
Indices to take along each 1d slice of ``arr``. This must match the
75+
dimension of ``arr``, but dimensions Ni and Nj only need to broadcast
76+
against ``arr``.
77+
axis : int or None, optional
7878
The axis to take 1d slices along. If axis is None, the input array is
7979
treated as if it had first been flattened to 1d, for consistency with
8080
`sort` and `argsort`.
8181
82+
.. versionchanged:: 2.3
83+
The default value is now ``-1``.
84+
8285
Returns
8386
-------
8487
out: ndarray (Ni..., J, Nk...)

numpy/lib/_shape_base_impl.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class _SupportsArrayWrap(Protocol):
7070
def take_along_axis(
7171
arr: _ScalarT | NDArray[_ScalarT],
7272
indices: NDArray[integer],
73-
axis: int | None,
73+
axis: int | None = ...,
7474
) -> NDArray[_ScalarT]: ...
7575

7676
def put_along_axis(

numpy/typing/tests/data/reveal/numeric.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ AR_O: npt.NDArray[np.object_]
2525
B: list[int]
2626
C: SubClass
2727

28-
assert_type(np.count_nonzero(i8), int)
29-
assert_type(np.count_nonzero(AR_i8), int)
30-
assert_type(np.count_nonzero(B), int)
28+
assert_type(np.count_nonzero(i8), np.intp)
29+
assert_type(np.count_nonzero(AR_i8), np.intp)
30+
assert_type(np.count_nonzero(B), np.intp)
3131
assert_type(np.count_nonzero(AR_i8, keepdims=True), npt.NDArray[np.intp])
3232
assert_type(np.count_nonzero(AR_i8, axis=0), Any)
3333

tools/ci/array-api-xfails.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,30 @@ array_api_tests/test_signatures.py::test_func_signature[vecdot]
2121

2222
# input is cast to min/max's dtype if they're different
2323
array_api_tests/test_operators_and_elementwise_functions.py::test_clip
24+
25+
# missing 'dtype' keyword argument
26+
array_api_tests/test_signatures.py::test_extension_func_signature[fft.fftfreq]
27+
array_api_tests/test_signatures.py::test_extension_func_signature[fft.rfftfreq]
28+
29+
# fails on np.repeat(np.array([]), np.array([])) test case
30+
array_api_tests/test_manipulation_functions.py::test_repeat
31+
32+
# NumPy matches Python behavior and it returns NaN and -1 in these cases
33+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
34+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
35+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
36+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
37+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
38+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
39+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
40+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
41+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
42+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
43+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
44+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
45+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
46+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
47+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
48+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
49+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
50+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy