diff --git a/numpy/core/src/umath/funcs.inc.src b/numpy/core/src/umath/funcs.inc.src index a76adaa39e6e..a8db99d5d968 100644 --- a/numpy/core/src/umath/funcs.inc.src +++ b/numpy/core/src/umath/funcs.inc.src @@ -54,6 +54,34 @@ npy_ObjectPower(PyObject *x, PyObject *y) return PyNumber_Power(x, y, Py_None); } + +#if defined(NPY_PY3K) +/**begin repeat + * #Kind = Max, Min# + * #OP = Py_GE, Py_LE# + */ +static PyObject * +npy_Object@Kind@(PyObject *i1, PyObject *i2) +{ + PyObject *result; + int cmp; + + cmp = PyObject_RichCompareBool(i1, i2, @OP@); + if (cmp < 0) { + return NULL; + } + if (cmp == 1) { + result = i1; + } + else { + result = i2; + } + Py_INCREF(result); + return result; +} +/**end repeat**/ + +#else /**begin repeat * #Kind = Max, Min# * #OP = >=, <=# @@ -77,6 +105,8 @@ npy_Object@Kind@(PyObject *i1, PyObject *i2) return result; } /**end repeat**/ +#endif + /* Emulates Python's 'a or b' behavior */ static PyObject * diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 88d52568c8e4..118e0b4dd8fc 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -929,25 +929,24 @@ class TestArgmax(TestCase): ([complex(1, 0), complex(0, 2), complex(0, 1)], 0), ([complex(1, 0), complex(0, 2), complex(1, 1)], 2), - # Fails on 32-bit systems (haven't tested 64-bit) due to y2.038k bug - #([np.datetime64('1923-04-14T12:43:12'), - # np.datetime64('1994-06-21T14:43:15'), - # np.datetime64('2001-10-15T04:10:32'), - # np.datetime64('1995-11-25T16:02:16'), - # np.datetime64('2005-01-04T03:14:12'), - # np.datetime64('2041-12-03T14:05:03')], 5), + ([np.datetime64('1923-04-14T12:43:12'), + np.datetime64('1994-06-21T14:43:15'), + np.datetime64('2001-10-15T04:10:32'), + np.datetime64('1995-11-25T16:02:16'), + np.datetime64('2005-01-04T03:14:12'), + np.datetime64('2041-12-03T14:05:03')], 5), ([np.datetime64('1935-09-14T04:40:11'), np.datetime64('1949-10-12T12:32:11'), np.datetime64('2010-01-03T05:14:12'), np.datetime64('2015-11-20T12:20:59'), np.datetime64('1932-09-23T10:10:13'), np.datetime64('2014-10-10T03:50:30')], 3), - #([np.datetime64('2059-03-14T12:43:12'), - # np.datetime64('1996-09-21T14:43:15'), - # np.datetime64('2001-10-15T04:10:32'), - # np.datetime64('2022-12-25T16:02:16'), - # np.datetime64('1963-10-04T03:14:12'), - # np.datetime64('2013-05-08T18:15:23')], 0), + ([np.datetime64('2059-03-14T12:43:12'), + np.datetime64('1996-09-21T14:43:15'), + np.datetime64('2001-10-15T04:10:32'), + np.datetime64('2022-12-25T16:02:16'), + np.datetime64('1963-10-04T03:14:12'), + np.datetime64('2013-05-08T18:15:23')], 0), ([timedelta(days=5, seconds=14), timedelta(days=2, seconds=35), timedelta(days=-1, seconds=23)], 0), @@ -998,25 +997,24 @@ class TestArgmin(TestCase): ([complex(1, 0), complex(0, 2), complex(0, 1)], 2), ([complex(1, 0), complex(0, 2), complex(1, 1)], 1), - # Fails on 32-bit systems (haven't tested 64-bit) due to y2.038k bug - #([np.datetime64('1923-04-14T12:43:12'), - # np.datetime64('1994-06-21T14:43:15'), - # np.datetime64('2001-10-15T04:10:32'), - # np.datetime64('1995-11-25T16:02:16'), - # np.datetime64('2005-01-04T03:14:12'), - # np.datetime64('2041-12-03T14:05:03')], 0), + ([np.datetime64('1923-04-14T12:43:12'), + np.datetime64('1994-06-21T14:43:15'), + np.datetime64('2001-10-15T04:10:32'), + np.datetime64('1995-11-25T16:02:16'), + np.datetime64('2005-01-04T03:14:12'), + np.datetime64('2041-12-03T14:05:03')], 0), ([np.datetime64('1935-09-14T04:40:11'), np.datetime64('1949-10-12T12:32:11'), np.datetime64('2010-01-03T05:14:12'), np.datetime64('2014-11-20T12:20:59'), np.datetime64('2015-09-23T10:10:13'), np.datetime64('1932-10-10T03:50:30')], 5), - #([np.datetime64('2059-03-14T12:43:12'), - # np.datetime64('1996-09-21T14:43:15'), - # np.datetime64('2001-10-15T04:10:32'), - # np.datetime64('2022-12-25T16:02:16'), - # np.datetime64('1963-10-04T03:14:12'), - # np.datetime64('2013-05-08T18:15:23')], 4), + ([np.datetime64('2059-03-14T12:43:12'), + np.datetime64('1996-09-21T14:43:15'), + np.datetime64('2001-10-15T04:10:32'), + np.datetime64('2022-12-25T16:02:16'), + np.datetime64('1963-10-04T03:14:12'), + np.datetime64('2013-05-08T18:15:23')], 4), ([timedelta(days=5, seconds=14), timedelta(days=2, seconds=35), timedelta(days=-1, seconds=23)], 2), diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 9c5ff8eef001..e6e1e593f0a7 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -470,6 +470,11 @@ def test_complex_nans(self): out = np.array([nan, nan, nan], dtype=np.complex) assert_equal(np.maximum(arg1, arg2), out) + def test_object_array(self): + arg1 = np.arange(5, dtype=np.object) + arg2 = arg1 + 1 + assert_equal(np.maximum(arg1, arg2), arg2) + class TestMinimum(TestCase): def test_reduce(self): @@ -512,6 +517,11 @@ def test_complex_nans(self): out = np.array([nan, nan, nan], dtype=np.complex) assert_equal(np.minimum(arg1, arg2), out) + def test_object_array(self): + arg1 = np.arange(5, dtype=np.object) + arg2 = arg1 + 1 + assert_equal(np.minimum(arg1, arg2), arg1) + class TestFmax(TestCase): def test_reduce(self):