Skip to content

Commit

Permalink
STY: Minor style cleanups in tests and C code.
Browse files Browse the repository at this point in the history
Also added back some extended error messages that were in original
PR numpy#5864.
  • Loading branch information
charris committed Jun 13, 2015
1 parent df148e1 commit 0aa3260
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
21 changes: 11 additions & 10 deletions numpy/core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,25 +953,25 @@ get_ufunc_arguments(PyUFuncObject *ufunc,
/* strcmp() is a hack but I think we can get away with it for this
* temporary measure.
*/
if (!strcmp(ufunc_name, "equal")
|| !strcmp(ufunc_name, "not_equal")) {
if (!strcmp(ufunc_name, "equal") ||
!strcmp(ufunc_name, "not_equal")) {
/* Warn on non-scalar, return NotImplemented regardless */
assert(nin == 2);
if (PyArray_NDIM(out_op[0]) != 0
|| PyArray_NDIM(out_op[1]) != 0) {
if (PyArray_NDIM(out_op[0]) != 0 ||
PyArray_NDIM(out_op[1]) != 0) {
if (DEPRECATE_FUTUREWARNING(
"elementwise comparison failed; returning scalar "
"but in the future will perform elementwise "
"instead, but in the future will perform elementwise "
"comparison") < 0) {
return -1;
}
}
return -2;
}
else if (!strcmp(ufunc_name, "less")
|| !strcmp(ufunc_name, "less_equal")
|| !strcmp(ufunc_name, "greater")
|| !strcmp(ufunc_name, "greater_equal")) {
else if (!strcmp(ufunc_name, "less") ||
!strcmp(ufunc_name, "less_equal") ||
!strcmp(ufunc_name, "greater") ||
!strcmp(ufunc_name, "greater_equal")) {
#if !defined(NPY_PY3K)
if (DEPRECATE("unorderable dtypes; returning scalar but in "
"the future this will be an error") < 0) {
Expand Down Expand Up @@ -4255,7 +4255,8 @@ ufunc_generic_call(PyUFuncObject *ufunc, PyObject *args, PyObject *kwds)
return NULL;
}
else if (ufunc->nin == 2 && ufunc->nout == 1) {
/* For array_richcompare's benefit -- see the long comment in
/*
* For array_richcompare's benefit -- see the long comment in
* get_ufunc_arguments.
*/
Py_INCREF(Py_NotImplemented);
Expand Down
20 changes: 12 additions & 8 deletions numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,26 @@ def assert_deprecated(self, function, num=1, ignore_others=False,
if warning.category is DeprecationWarning:
num_found += 1
elif not ignore_others:
raise AssertionError("expected DeprecationWarning but %s given"
% warning.category)
raise AssertionError(
"expected DeprecationWarning but got: %s" %
(repr_warning_message(warning),))
if num is not None and num_found != num:
raise AssertionError("%i warnings found but %i expected"
% (len(self.log), num))
msg = "%i warnings found but %i expected." % (len(self.log), num)
lst = [repr_warning_message(w) for w in self.log]
raise AssertionError("\n".join([msg] + [lst]))

with warnings.catch_warnings():
warnings.filterwarnings("error", message=self.message,
category=DeprecationWarning)

category=DeprecationWarning)
try:
function(*args, **kwargs)
if exceptions != tuple():
raise AssertionError("No error raised during function call")
raise AssertionError(
"No error raised during function call")
except exceptions:
if exceptions == tuple():
raise AssertionError("Error raised during function call")
raise AssertionError(
"Error raised during function call")

def assert_not_deprecated(self, function, args=(), kwargs={}):
"""Test if DeprecationWarnings are given and raised.
Expand Down Expand Up @@ -494,6 +497,7 @@ def test_array_richcompare_legacy_weirdness(self):
# py2
assert_warns(DeprecationWarning, f, arg1, arg2)


class TestIdentityComparisonDeprecations(_DeprecationTestCase):
"""This tests the equal and not_equal object ufuncs identity check
deprecation. This was due to the usage of PyObject_RichCompareBool.
Expand Down

0 comments on commit 0aa3260

Please sign in to comment.