Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release/upcoming_changes/30803.compatibility.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
``numpy.where`` no longer truncates Python integers
---------------------------------------------------

Previously, if the ``x`` or ``y`` argument of ``numpy.where`` was a Python integer
that was out of range of the output type, it would be silently truncated.
Now, an `OverflowError` will be raised instead.

This change also applies to the underlying C API function ``PyArray_Where``.
3 changes: 3 additions & 0 deletions numpy/_core/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ def concatenate(arrays, axis=0, out=None, *, dtype=None, casting="same_kind"):

Join a sequence of arrays along an existing axis.

.. versionadded:: 2.0
``numpy.concat`` added as a shorthand for ``numpy.concatenate``.

Parameters
----------
a1, a2, ... : sequence of array_like
Expand Down
5 changes: 3 additions & 2 deletions numpy/_core/src/common/cblasfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ _bad_strides(PyArrayObject *ap)
* __array_ufunc__ nonsense is also assumed to have been taken care of.
*/
NPY_NO_EXPORT PyObject *
cblas_matrixproduct(int typenum, PyArrayObject *ap1, PyArrayObject *ap2,
cblas_matrixproduct(PyArray_Descr *typec, PyArrayObject *ap1, PyArrayObject *ap2,
PyArrayObject *out)
{
PyArrayObject *result = NULL, *out_buf = NULL;
int typenum = typec->type_num;
npy_intp j, lda, ldb;
npy_intp l;
int nd;
Expand Down Expand Up @@ -364,7 +365,7 @@ cblas_matrixproduct(int typenum, PyArrayObject *ap1, PyArrayObject *ap2,
}
}

out_buf = new_array_for_sum(ap1, ap2, out, nd, dimensions, typenum, &result);
out_buf = new_array_for_sum(ap1, ap2, out, nd, dimensions, typec, &result);
if (out_buf == NULL) {
goto fail;
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/src/common/cblasfuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define NUMPY_CORE_SRC_COMMON_CBLASFUNCS_H_

NPY_NO_EXPORT PyObject *
cblas_matrixproduct(int, PyArrayObject *, PyArrayObject *, PyArrayObject *);
cblas_matrixproduct(PyArray_Descr *, PyArrayObject *, PyArrayObject *, PyArrayObject *);

#endif /* NUMPY_CORE_SRC_COMMON_CBLASFUNCS_H_ */
13 changes: 7 additions & 6 deletions numpy/_core/src/multiarray/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ _may_have_objects(PyArray_Descr *dtype)
*/
NPY_NO_EXPORT PyArrayObject *
new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,
int nd, npy_intp dimensions[], int typenum, PyArrayObject **result)
int nd, npy_intp dimensions[], PyArray_Descr *descr, PyArrayObject **result)
{
PyArrayObject *out_buf;

Expand All @@ -390,7 +390,7 @@ new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,

/* verify that out is usable */
if (PyArray_NDIM(out) != nd ||
PyArray_TYPE(out) != typenum ||
!PyArray_EquivTypes(PyArray_DESCR(out), descr) ||
!PyArray_ISCARRAY(out)) {
PyErr_SetString(PyExc_ValueError,
"output array is not acceptable (must have the right datatype, "
Expand Down Expand Up @@ -452,10 +452,11 @@ new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,
subtype = Py_TYPE(ap1);
}

out_buf = (PyArrayObject *)PyArray_New(subtype, nd, dimensions,
typenum, NULL, NULL, 0, 0,
(PyObject *)
(prior2 > prior1 ? ap2 : ap1));
Py_INCREF(descr);
out_buf = (PyArrayObject *)PyArray_NewFromDescr(subtype, descr, nd, dimensions,
NULL, NULL, 0,
(PyObject *)
(prior2 > prior1 ? ap2 : ap1));

if (out_buf != NULL && result) {
Py_INCREF(out_buf);
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/src/multiarray/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ check_is_convertible_to_scalar(PyArrayObject *v);
*/
NPY_NO_EXPORT PyArrayObject *
new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject* out,
int nd, npy_intp dimensions[], int typenum, PyArrayObject **result);
int nd, npy_intp dimensions[], PyArray_Descr *descr, PyArrayObject **result);


/*
Expand Down
Loading