diff --git a/sparse/_sparse_array.py b/sparse/_sparse_array.py index 4418b2e6..0737fe44 100644 --- a/sparse/_sparse_array.py +++ b/sparse/_sparse_array.py @@ -229,6 +229,7 @@ def __array__(self, **kwargs): def __array_function__(self, func, types, args, kwargs): import sparse as module + sparse_func = None try: submodules = getattr(func, "__module__", "numpy").split(".")[1:] for submodule in submodules: @@ -242,9 +243,19 @@ def __array_function__(self, func, types, args, kwargs): try: sparse_func = getattr(type(self), func.__name__) except AttributeError: - return NotImplemented + pass - if not isinstance(sparse_func, Callable): - return getattr(self, func.__name__) + if ( + not isinstance(sparse_func, Callable) + and len(args) == 1 + and len(kwargs) == 0 + ): + try: + return getattr(self, func.__name__) + except AttributeError: + pass + + if sparse_func is None: + return NotImplemented return sparse_func(*args, **kwargs) diff --git a/sparse/tests/test_array_function.py b/sparse/tests/test_array_function.py index a0ee7240..b31d4fae 100644 --- a/sparse/tests/test_array_function.py +++ b/sparse/tests/test_array_function.py @@ -66,3 +66,12 @@ def test_ternary(func, arg_order): args = [(x, y)[i] for i in arg_order] yy = func(*args) assert_eq(xx, yy) + + +@pytest.mark.parametrize("func", [np.shape, np.size, np.ndim]) +def test_property(func): + y = sparse.random((50, 50), density=0.25) + x = y.todense() + xx = func(x) + yy = func(y) + assert xx == yy