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
10 changes: 10 additions & 0 deletions doc/release/upcoming_changes/29052.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Positional ``out`` argument to `np.maximum`, `np.minimum` is deprecated
-----------------------------------------------------------------------
Passing the output array ``out`` positionally to `numpy.maximum` and
`numpy.minimum` is deprecated. For example, ``np.maximum(a, b, c)`` will
emit a deprecation warning, since ``c`` is treated as the output buffer
rather than a third input.

Always pass the output with the keyword form, e.g.
``np.maximum(a, b, out=c)``. This makes intent clear and simplifies
type annotations.
16 changes: 16 additions & 0 deletions numpy/_core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "mapping.h"
#include "npy_static_data.h"
#include "multiarraymodule.h"
#include "number.h"

/********** PRINTF DEBUG TRACING **************/
#define NPY_UF_DBG_TRACING 0
Expand Down Expand Up @@ -4368,6 +4369,21 @@ ufunc_generic_fastcall(PyUFuncObject *ufunc,
Py_INCREF(tmp);
PyTuple_SET_ITEM(full_args.out, i-nin, tmp);
}

/* Extra positional args but no keywords */
/* DEPRECATED NumPy 2.4, 2025-08 */
if ((PyObject *)ufunc == n_ops.maximum || (PyObject *)ufunc == n_ops.minimum) {

if (DEPRECATE(
"Passing more than 2 positional arguments to np.maximum and np.minimum "
"is deprecated. If you meant to use the third argument as an output, "
"use the `out` keyword argument instead. If you hoped to work with "
"more than 2 inputs, combine them into a single array and get the extrema "
"for the relevant axis.") < 0) {
return NULL;
}
}

if (all_none) {
Py_SETREF(full_args.out, NULL);
}
Expand Down
9 changes: 9 additions & 0 deletions numpy/_core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,12 @@ def use_suppress_warnings():
sup.filter(RuntimeWarning, 'invalid value encountered in divide')

self.assert_deprecated(use_suppress_warnings)


class TestTooManyArgsExtremum(_DeprecationTestCase):
# Deprecated in Numpy 2.4, 2025-08, gh-27639
message = "Passing more than 2 positional arguments to np.maximum and np.minimum "

@pytest.mark.parametrize("ufunc", [np.minimum, np.maximum])
def test_extremem_3_args(self, ufunc):
self.assert_deprecated(ufunc, args=(np.ones(1), np.zeros(1), np.empty(1)))
Loading