8000 BUG: do not emit warnings for np.sign, np.equal when using nan by mattip · Pull Request #15209 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: do not emit warnings for np.sign, np.equal when using nan #15209

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions numpy/core/src/umath/loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ NPY_NO_EXPORT void
*((npy_bool *)op1) = in1 @OP@ in2;
}
}
npy_clear_floatstatus_barrier((char*)dimensions);
}
/**end repeat1**/

Expand Down Expand Up @@ -2068,6 +2069,7 @@ NPY_NO_EXPORT void
const @type@ in1 = *(@type@ *)ip1;
*((@type@ *)op1) = in1 > 0 ? 1 : (in1 < 0 ? -1 : (in1 == 0 ? 0 : in1));
}
npy_clear_floatstatus_barrier((char*)dimensions);
}

NPY_NO_EXPORT void
Expand Down
24 changes: 24 additions & 0 deletions numpy/core/tests/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,3 +1984,27 @@ def test_ufunc_noncontiguous(ufunc):
assert_allclose(res_c, res_n, atol=tol, rtol=tol)
else:
assert_equal(c_ar, n_ar)


@pytest.mark.parametrize('ufunc', [np.sign, np.equal])
def test_ufunc_warn_with_nan(ufunc):
# issue gh-15127
# test that calling certain ufuncs with a non-standard `nan` value does not
# emit a warning
a = np.packbits([0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1])
b = a.view(np.float64)
assert np.isnan(b)
if ufunc.nin == 1:
ufunc(b)
elif ufunc.nin == 2:
ufunc(b, b.copy())
else:
raise ValueError('ufunc with more than 2 inputs')

0