8000 BUG: Fix PyObject_Cmp in npy_3kcompat.h. by charris · Pull Request #6386 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix PyObject_Cmp in npy_3kcompat.h. #6386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2015
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
BUG: Fix PyObject_Cmp in npy_3kcompat.h.
The old version was interpreting a PyObject_RichCompareBool return of 0
as success when it actually means failure. The fix is to replace 0 by 1.
  • Loading branch information
charris committed Sep 28, 2015
commit 549572191f68ccf874fca4c8e395c5ec0c870ddb
6 changes: 3 additions & 3 deletions numpy/core/include/numpy/npy_3kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
{
int v;
v = PyObject_RichCompareBool(i1, i2, Py_LT);
if (v == 0) {
if (v == 1) {
*cmp = -1;
return 1;
}
Expand All @@ -334,7 +334,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
}

v = PyObject_RichCompareBool(i1, i2, Py_GT);
if (v == 0) {
if (v == 1) {
*cmp = 1;
return 1;
}
Expand All @@ -343,7 +343,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
}

v = PyObject_RichCompareBool(i1, i2, Py_EQ);
if (v == 0) {
if (v == 1) {
*cmp = 0;
return 1;
}
Expand Down
7 changes: 7 additions & 0 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,13 @@ def test_sign(self):
assert_equal(res, tgt)
assert_equal(out, tgt)

def test_sign_dtype_object(self):
# In reference to github issue #6229
foo = np.array([-.1, 0, .1])
a = np.sign(foo.astype(np.object))
b = np.sign(foo)
assert_array_equal(a, b)


class TestMinMax(TestCase):
def test_minmax_blocked(self):
Expand Down
0