summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-04-11 22:40:37 -0700
committerTyler Reddy <tyler.je.reddy@gmail.com>2019-05-14 13:52:36 -0700
commited825fb2823c60de45950cab286ccc5cf9a2cdcb (patch)
tree33f6194d2a91b2312549e9de295e0c2847946a7b
parent6492f632a92439c82c74efa6753e10ce9360c6ba (diff)
downloadnumpy-ed825fb2823c60de45950cab286ccc5cf9a2cdcb.tar.gz
BUG: Restore the old non-object behavior for min > max
This changes the object array behavior to match the other behavior
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py2
-rw-r--r--numpy/core/src/umath/clip.c.src2
-rw-r--r--numpy/core/src/umath/funcs.inc.src4
-rw-r--r--numpy/core/tests/test_numeric.py10
4 files changed, 9 insertions, 9 deletions
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py
index 26170b2ae..6a5def4f2 100644
--- a/numpy/core/code_generators/ufunc_docstrings.py
+++ b/numpy/core/code_generators/ufunc_docstrings.py
@@ -2550,7 +2550,7 @@ add_newdoc('numpy.core.umath', 'clip',
is specified, values smaller than 0 become 0, and values larger
than 1 become 1.
- Equivalent to but faster than ``np.maximum(a_min, np.minimum(a, a_max))``.
+ Equivalent to but faster than ``np.minimum(np.maximum(a, a_min), a_max)``.
Parameters
----------
diff --git a/numpy/core/src/umath/clip.c.src b/numpy/core/src/umath/clip.c.src
index ad9a0864b..30fa3d2b3 100644
--- a/numpy/core/src/umath/clip.c.src
+++ b/numpy/core/src/umath/clip.c.src
@@ -76,7 +76,7 @@
*/
#define _NPY_CLIP(x, min, max) \
- _NPY_@name@_MAX(_NPY_@name@_MIN((x), (max)), (min))
+ _NPY_@name@_MIN(_NPY_@name@_MAX((x), (min)), (max))
NPY_NO_EXPORT void
@name@_clip(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func))
diff --git a/numpy/core/src/umath/funcs.inc.src b/numpy/core/src/umath/funcs.inc.src
index 555990ca8..c2732f925 100644
--- a/numpy/core/src/umath/funcs.inc.src
+++ b/numpy/core/src/umath/funcs.inc.src
@@ -262,11 +262,11 @@ npy_ObjectLCM(PyObject *i1, PyObject *i2)
static PyObject *
npy_ObjectClip(PyObject *arr, PyObject *min, PyObject *max) {
- PyObject *o = npy_ObjectMin(arr, max);
+ PyObject *o = npy_ObjectMax(arr, min);
if (o == NULL) {
return NULL;
}
- Py_SETREF(o, npy_ObjectMax(o, min));
+ Py_SETREF(o, npy_ObjectMin(o, max));
return o;
}
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 5e482b00a..ae596ec20 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1854,7 +1854,7 @@ class TestClip(object):
def test_clip_value_min_max_flip(self, amin, amax):
a = np.arange(10, dtype=np.int64)
# requirement from ufunc_docstrings.py
- expected = np.maximum(amin, np.minimum(a, amax))
+ expected = np.minimum(np.maximum(a, amin), amax)
actual = np.clip(a, amin, amax)
assert_equal(actual, expected)
@@ -1863,8 +1863,8 @@ class TestClip(object):
# case produced by hypothesis
(np.zeros(10, dtype=np.int64),
0,
- -9223372036854775809,
- np.zeros(10, dtype=object)),
+ -2**64+1,
+ np.full(10, -2**64+1, dtype=object)),
# for bugs in NPY_TIMEDELTA_MAX, based on a case
# produced by hypothesis
(np.zeros(10, dtype='m8') - 1,
@@ -1886,7 +1886,7 @@ class TestClip(object):
def test_clip_scalar_nan_propagation(self, arr, amin, amax):
# enforcement of scalar nan propagation for comparisons
# called through clip()
- expected = np.maximum(amin, np.minimum(arr, amax))
+ expected = np.minimum(np.maximum(a, amin), amax)
with assert_warns(DeprecationWarning):
actual = np.clip(arr, amin, amax)
assert_equal(actual, expected)
@@ -1900,7 +1900,7 @@ class TestClip(object):
def test_NaT_propagation(self, arr, amin, amax):
# NOTE: the expected function spec doesn't
# propagate NaT, but clip() now does
- expected = np.maximum(amin, np.minimum(arr, amax))
+ expected = np.minimum(np.maximum(a, amin), amax)
actual = np.clip(arr, amin, amax)
assert_equal(actual, expected)