8000 Merge pull request #6386 from charris/backport-PyObject_Cmp-fix · numpy/numpy@9871ed4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9871ed4

Browse files
committed
Merge pull request #6386 from charris/backport-PyObject_Cmp-fix
BUG: Fix PyObject_Cmp in npy_3kcompat.h.
2 parents aa8adf4 + 5495721 commit 9871ed4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

numpy/core/include/numpy/npy_3kcompat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
325325
{
326326
int v;
327327
v = PyObject_RichCompareBool(i1, i2, Py_LT);
328-
if (v == 0) {
328+
if (v == 1) {
329329
*cmp = -1;
330330
return 1;
331331
}
@@ -334,7 +334,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
334334
}
335335

336336
v = PyObject_RichCompareBool(i1, i2, Py_GT);
337-
if (v == 0) {
337+
if (v == 1) {
338338
*cmp = 1;
339339
return 1;
340340
}
@@ -343,7 +343,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
343343
}
344344

345345
v = PyObject_RichCompareBool(i1, i2, Py_EQ);
346-
if (v == 0) {
346+
if (v == 1) {
347347
*cmp = 0;
348348
return 1;
349349
}

numpy/core/tests/test_umath.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,13 @@ def test_sign(self):
935935
assert_equal(res, tgt)
936936
assert_equal(out, tgt)
937937

938+
def test_sign_dtype_object(self):
939+
# In reference to github issue #6229
940+
foo = np.array([-.1, 0, .1])
941+
a = np.sign(foo.astype(np.object))
942+
b = np.sign(foo)
943+
assert_array_equal(a, b)
944+
938945

939946
class TestMinMax(TestCase):
940947
def test_minmax_blocked(self):

0 commit comments

Comments
 (0)
0