10000 Merge branch 'numpy:main' into main · numpy/numpy@5f8a20f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f8a20f

Browse files
authored
Merge branch 'numpy:main' into main
2 parents 559dc78 + 441e280 commit 5f8a20f

File tree

10 files changed

+43
-29
lines changed

10 files changed

+43
-29
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747

4848
# Initializes the CodeQL tools for scanning.
4949
- name: Initialize CodeQL
50-
uses: github/codeql-action/init@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
50+
uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
5151
with:
5252
languages: ${{ matrix.language }}
5353
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -57,7 +57,7 @@ jobs:
5757
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5858
# If this step fails, then you should remove it and run the build manually (see below)
5959
- name: Autobuild
60-
uses: github/codeql-action/autobuild@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
60+
uses: github/codeql-action/autobuild@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
6161

6262
# ℹ️ Command-line programs to run using the OS shell.
6363
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -70,6 +70,6 @@ jobs:
7070
# ./location_of_script_within_repo/buildscript.sh
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
73+
uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
7474
with:
7575
category: "/language:${{matrix.language}}"

.github/workflows/scorecards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ jobs:
5050

5151
# Upload the results to GitHub's code scanning dashboard.
5252
- name: "Upload to code-scanning"
53-
uses: github/codeql-action/upload-sarif@45775bd8235c68ba998cffa5171334d58593da47 # v2.1.27
53+
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v2.1.27
5454
with:
5555
sarif_file: results.sarif

numpy/_core/src/multiarray/convert_datatype.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,13 +1597,12 @@ PyArray_ResultType(
15971597
return NULL;
15981598
}
15991599

1600-
PyArray_DTypeMeta **all_DTypes = (PyArray_DTypeMeta **)workspace;
1600+
PyArray_DTypeMeta **all_DTypes = (PyArray_DTypeMeta **)workspace; // borrowed references
16011601
PyArray_Descr **all_descriptors = (PyArray_Descr **)(&all_DTypes[narrs+ndtypes]);
16021602

16031603
/* Copy all dtypes into a single array defining non-value-based behaviour */
16041604
for (npy_intp i=0; i < ndtypes; i++) {
16051605
all_DTypes[i] = NPY_DTYPE(descrs[i]);
1606-
Py_INCREF(all_DTypes[i]);
16071606
all_descriptors[i] = descrs[i];
16081607
}
16091608

@@ -1628,14 +1627,10 @@ PyArray_ResultType(
16281627
all_descriptors[i_all] = PyArray_DTYPE(arrs[i]);
16291628
all_DTypes[i_all] = NPY_DTYPE(all_descriptors[i_all]);
16301629
}
1631-
Py_INCREF(all_DTypes[i_all]);
16321630
}
16331631

16341632
PyArray_DTypeMeta *common_dtype = PyArray_PromoteDTypeSequence(
16351633
narrs+ndtypes, all_DTypes);
1636-
for (npy_intp i=0; i < narrs+ndtypes; i++) {
1637-
Py_DECREF(all_DTypes[i]);
1638-
}
16391634
if (common_dtype == NULL) {
16401635
goto error;
16411636
}

numpy/_core/src/multiarray/multiarraymodule.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,24 +3583,28 @@ static PyObject *
35833583
array_result_type(PyObject *NPY_UNUSED(dummy), PyObject *const *args, Py_ssize_t len)
35843584
{
35853585
npy_intp i, narr = 0, ndtypes = 0;
3586-
PyArrayObject **arr = NULL;
3587-
PyArray_Descr **dtypes = NULL;
35883586
PyObject *ret = NULL;
35893587

35903588
if (len == 0) {
35913589
PyErr_SetString(PyExc_ValueError,
35923590
"at least one array or dtype is required");
3593-
goto finish;
3591+
return NULL;
35943592
}
35953593

3596-
arr = PyArray_malloc(2 * len * sizeof(void *));
3594+
NPY_ALLOC_WORKSPACE(arr, PyArrayObject *, 2 * 3, 2 * len);
35973595
if (arr == NULL) {
3598-
return PyErr_NoMemory();
3596+
return NULL;
35993597
}
3600-
dtypes = (PyArray_Descr**)&arr[len];
3598+
PyArray_Descr **dtypes = (PyArray_Descr**)&arr[len];
3599+
3600+
PyObject *previous_obj = NULL;
36013601

36023602
for (i = 0; i < len; ++i) {
36033603
PyObject *obj = args[i];
3604+
if (obj == previous_obj) {
3605+
continue;
3606+
}
3607+
36043608
if (PyArray_Check(obj)) {
36053609
Py_INCREF(obj);
36063610
arr[narr] = (PyArrayObject *)obj;
@@ -3636,7 +3640,7 @@ array_result_type(PyObject *NPY_UNUSED(dummy), PyObject *const *args, Py_ssize_t
36363640
for (i = 0; i < ndtypes; ++i) {
36373641
Py_DECREF(dtypes[i]);
36383642
}
3639-
PyArray_free(arr);
3643+
npy_free_workspace(arr);
36403644
return ret;
36413645
}
36423646

numpy/_core/src/umath/string_fastsearch.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,16 +670,8 @@ preprocess(CheckedIndexer<char_type> needle, Py_ssize_t len_needle,
670670
assert(p->period + p->cut <= len_needle);
671671

672672
// Compare parts of the needle to check for periodicity.
673-
int cmp;
674-
if (std::is_same<char_type, npy_ucs4>::value) {
675-
cmp = memcmp(needle.buffer,
676-
needle.buffer + (p->period * sizeof(npy_ucs4)),
677-
(size_t) p->cut);
678-
}
679-
else {
680-
cmp = memcmp(needle.buffer, needle.buffer + p->period,
681-
(size_t) p->cut);
682-
}
673+
int cmp = memcmp(needle.buffer, needle.buffer + p->period,
674+
(size_t) p->cut);
683675
p->is_periodic = (0 == cmp);
684676

685677
// If periodic, gap is unused; otherwise, calculate period and gap.

numpy/_core/tests/test_strings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ def test_str_len(self, in_, out, dt):
381381
None, [3, -1]),
382382
("Ae¢☃€ 😊" * 2, "😊", 0, None, 6),
383383
("Ae¢☃€ 😊" * 2, "😊", 7, None, 13),
384+
pytest.param("A" * (2 ** 17), r"[\w]+\Z", 0, None, -1,
385+
id=r"A*2**17-[\w]+\Z-0-None--1"),
384386
])
385387
def test_find(self, a, sub, start, end, out, dt):
386388
if "😊" in a and dt == "S":

numpy/ma/core.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,11 @@ outerproduct = outer
11841184

11851185
def correlate(a, v, mode=..., propagate_mask=...): ...
11861186
def convolve(a, v, mode=..., propagate_mask=...): ...
1187-
def allequal(a, b, fill_value=...): ...
1188-
def allclose(a, b, masked_equal=..., rtol=..., atol=...): ...
1187+
1188+
def allequal(a: ArrayLike, b: ArrayLike, fill_value: bool = True) -> bool: ...
1189+
1190+
def allclose(a: ArrayLike, b: ArrayLike, masked_equal: bool = True, rtol: float = 1e-5, atol: float = 1e-8) -> bool: ...
1191+
11891192
def asarray(a, dtype=..., order=...): ...
11901193
def asanyarray(a, dtype=...): ...
11911194
def fromflex(fxarray): ...

numpy/testing/_private/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,11 @@ def run_threaded(func, max_workers=8, pass_count=False,
27412741
futures = []
27422742
for arg in all_args:
27432743
futures.append(tpe.submit(*arg))
2744+
except RuntimeError as e:
2745+
import pytest
2746+
pytest.skip(f"Spawning {max_workers} threads failed with "
2747+
f"error {e!r} (likely due to resource limits on the "
2748+
"system running the tests)")
27442749
finally:
27452750
if len(futures) < max_workers and pass_barrier:
27462751
barrier.abort()

numpy/typing/tests/data/fail/ma.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,9 @@ np.ma.put(m, 4, 999, mode='flip') # E: No overload variant
116116
np.ma.put([1,1,3], 0, 999) # E: No overload variant
117117

118118
np.ma.compressed(lambda: 'compress me') # E: No overload variant
119+
120+
np.ma.allequal(m, [1,2,3], fill_value=1.5) # E: No overload variant
121+
122+
np.ma.allclose(m, [1,2,3], masked_equal=4.5) # E: No overload variant
123+
np.ma.allclose(m, [1,2,3], rtol='.4') # E: No overload variant
124+
np.ma.allclose(m, [1,2,3], atol='.5') # E: No overload variant

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,10 @@ assert_type(np.ma.filled([[1,2,3]]), NDArray[Any])
273273
# PyRight detects this one correctly, but mypy doesn't.
274274
# https://github.com/numpy/numpy/pull/28742#discussion_r2048968375
275275
assert_type(np.ma.filled(MAR_1d), np.ndarray[tuple[int], np.dtype]) # type: ignore[assert-type]
276+
277+
assert_type(np.ma.allequal(AR_f4, MAR_f4), bool)
278+
assert_type(np.ma.allequal(AR_f4, MAR_f4, fill_value=False), bool)
279+
280+
assert_type(np.ma.allclose(AR_f4, MAR_f4), bool)
281+
assert_type(np.ma.allclose(AR_f4, MAR_f4, masked_equal=False), bool)
282+
assert_type(np.ma.allclose(AR_f4, MAR_f4, rtol=.4, atol=.3), bool)

0 commit comments

Comments
 (0)
0