Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed825fb

Browse filesBrowse files
eric-wiesertylerjereddy
authored andcommitted
BUG: Restore the old non-object behavior for min > max
This changes the object array behavior to match the other behavior
1 parent 6492f63 commit ed825fb
Copy full SHA for ed825fb

File tree

Expand file treeCollapse file tree

4 files changed

+9
-9
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+9
-9
lines changed

‎numpy/core/code_generators/ufunc_docstrings.py

Copy file name to clipboardExpand all lines: numpy/core/code_generators/ufunc_docstrings.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ def add_newdoc(place, name, doc):
25502550
is specified, values smaller than 0 become 0, and values larger
25512551
than 1 become 1.
25522552
2553-
Equivalent to but faster than ``np.maximum(a_min, np.minimum(a, a_max))``.
2553+
Equivalent to but faster than ``np.minimum(np.maximum(a, a_min), a_max)``.
25542554
25552555
Parameters
25562556
----------

‎numpy/core/src/umath/clip.c.src

Copy file name to clipboardExpand all lines: numpy/core/src/umath/clip.c.src
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
*/
7777

7878
#define _NPY_CLIP(x, min, max) \
79-
_NPY_@name@_MAX(_NPY_@name@_MIN((x), (max)), (min))
79+
_NPY_@name@_MIN(_NPY_@name@_MAX((x), (min)), (max))
8080

8181
NPY_NO_EXPORT void
8282
@name@_clip(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func))

‎numpy/core/src/umath/funcs.inc.src

Copy file name to clipboardExpand all lines: numpy/core/src/umath/funcs.inc.src
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ npy_ObjectLCM(PyObject *i1, PyObject *i2)
262262

263263
static PyObject *
264264
npy_ObjectClip(PyObject *arr, PyObject *min, PyObject *max) {
265-
PyObject *o = npy_ObjectMin(arr, max);
265+
PyObject *o = npy_ObjectMax(arr, min);
266266
if (o == NULL) {
267267
return NULL;
268268
}
269-
Py_SETREF(o, npy_ObjectMax(o, min));
269+
Py_SETREF(o, npy_ObjectMin(o, max));
270270
return o;
271271
}
272272

‎numpy/core/tests/test_numeric.py

Copy file name to clipboardExpand all lines: numpy/core/tests/test_numeric.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ def test_clip_invalid_casting(self):
18541854
def test_clip_value_min_max_flip(self, amin, amax):
18551855
a = np.arange(10, dtype=np.int64)
18561856
# requirement from ufunc_docstrings.py
1857-
expected = np.maximum(amin, np.minimum(a, amax))
1857+
expected = np.minimum(np.maximum(a, amin), amax)
18581858
actual = np.clip(a, amin, amax)
18591859
assert_equal(actual, expected)
18601860

@@ -1863,8 +1863,8 @@ def test_clip_value_min_max_flip(self, amin, amax):
18631863
# case produced by hypothesis
18641864
(np.zeros(10, dtype=np.int64),
18651865
0,
1866-
-9223372036854775809,
1867-
np.zeros(10, dtype=object)),
1866+
-2**64+1,
1867+
np.full(10, -2**64+1, dtype=object)),
18681868
# for bugs in NPY_TIMEDELTA_MAX, based on a case
18691869
# produced by hypothesis
18701870
(np.zeros(10, dtype='m8') - 1,
@@ -1886,7 +1886,7 @@ def test_clip_problem_cases(self, arr, amin, amax, exp):
18861886
def test_clip_scalar_nan_propagation(self, arr, amin, amax):
18871887
# enforcement of scalar nan propagation for comparisons
18881888
# called through clip()
1889-
expected = np.maximum(amin, np.minimum(arr, amax))
1889+
expected = np.minimum(np.maximum(a, amin), amax)
18901890
with assert_warns(DeprecationWarning):
18911891
actual = np.clip(arr, amin, amax)
18921892
assert_equal(actual, expected)
@@ -1900,7 +1900,7 @@ def test_clip_scalar_nan_propagation(self, arr, amin, amax):
19001900
def test_NaT_propagation(self, arr, amin, amax):
19011901
# NOTE: the expected function spec doesn't
19021902
# propagate NaT, but clip() now does
1903-
expected = np.maximum(amin, np.minimum(arr, amax))
1903+
expected = np.minimum(np.maximum(a, amin), amax)
19041904
actual = np.clip(arr, amin, amax)
19051905
assert_equal(actual, expected)
19061906

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.