8000 ENH: `__array_function__` support for `np.lib`, part 2/2 by shoyer · Pull Request #12119 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: __array_function__ support for np.lib, part 2/2 #12119

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 15 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix failures in numpy/core/tests/test_overrides.py
  • Loading branch information
shoyer committed Oct 9, 2018
commit d019e8fd1392c06bb0bb102a18290fef292b1c1c
25 changes: 13 additions & 12 deletions numpy/core/tests/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def _get_overloaded_args(relevant_args):
return args


def _return_self(self, *args, **kwargs):
return self
def _return_not_implemented(self, *args, **kwargs):
return NotImplemented


class TestGetOverloadedTypesAndArgs(object):
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_ndarray(self):
def test_ndarray_subclasses(self):

class OverrideSub(np.ndarray):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class NoOverrideSub(np.ndarray):
pass
Expand All @@ -70,7 +70,7 @@ class NoOverrideSub(np.ndarray):
def test_ndarray_and_duck_array(self):

class Other(object):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

array = np.array(1)
other = Other()
Expand All @@ -86,10 +86,10 @@ class Other(object):
def test_ndarray_subclass_and_duck_array(self):

class OverrideSub(np.ndarray):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class Other(object):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

array = np.array(1)
subarray = np.array(1).view(OverrideSub)
Expand All @@ -103,16 +103,16 @@ class Other(object):
def test_many_duck_arrays(self):

class A(object):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class B(A):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class C(A):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class D(object):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

a = A()
b = B()
Expand All @@ -135,7 +135,7 @@ class TestNDArrayArrayFunction(object):
def test_method(self):

class SubOverride(np.ndarray):
__array_function__ = _return_self
__array_function__ = _return_not_implemented

class NoOverrideSub(np.ndarray):
pass
Expand Down Expand Up @@ -187,7 +187,8 @@ def __array_function__(self, func, types, args, kwargs):
assert_(obj is original)
assert_(func is dispatched_one_arg)
assert_equal(set(types), {MyArray})
assert_equal(args, (original,))
# assert_equal uses the overloaded np.iscomplexobj() internally
assert_(args == (original,))
assert_equal(kwargs, {})

def test_not_implemented(self):
Expand Down
2 changes: 1 addition & 1 deletion numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
# XXX: catch ValueError for subclasses of ndarray where iscomplex fail
try:
usecomplex = iscomplexobj(actual) or iscomplexobj(desired)
except ValueError:
except (ValueError, TypeError):
usecomplex = False

if usecomplex:
Expand Down
0