8000 MAINT: revert __skip_array_function__ from NEP-18 by shoyer · Pull Request #13627 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: revert __skip_array_function__ from NEP-18 #13627

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 3 commits into from
May 28, 2019
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
Tests for NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0
  • Loading branch information
shoyer committed May 25, 2019
commit 37df5e641f19d9e5221cb519532b6cc5647ebe53
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ matrix:
env: NPY_RELAXED_STRIDES_CHECKING=0
- python: 3.6
env: USE_WHEEL=1 NPY_RELAXED_STRIDES_DEBUG=1
- python: 3.6
env: NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consolidate this CI run into one of the others?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get 5 parallel runs and we are already over 10, so as long as there are fewer than 15 test runs it shouldn't make much difference. The runs vary in time, so it isn't possible to predict exactly what will happen, but close enough.

- python: 3.6
env:
- BLAS=None
Expand Down
11 changes: 2 additions & 9 deletions numpy/core/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,9 @@ def array_function_dispatch(dispatcher, module=None, verify=True,
def decorator(implementation):
if docs_from_dispatcher:
add_docstring(implementation, dispatcher.__doc__)

public_api = implementation

if module is not None:
public_api.__module__ = module

public_api._implementation = implementation

return public_api

implementation.__module__ = module
return implementation
return decorator

def decorator(implementation):
Expand Down
17 changes: 15 additions & 2 deletions numpy/core/tests/test_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
assert_, assert_equal, assert_raises, assert_raises_regex)
from numpy.core.overrides import (
_get_implementing_args, array_function_dispatch,
verify_matching_signatures)
verify_matching_signatures, ENABLE_ARRAY_FUNCTION)
from numpy.compat import pickle
import pytest


requires_array_function = pytest.mark.skipif(
not ENABLE_ARRAY_FUNCTION,
reason="__array_function__ dispatch not enabled.")


def _return_not_implemented(self, *args, **kwargs):
Expand Down Expand Up @@ -143,6 +149,7 @@ def test_too_many_duck_arrays(self):

class TestNDArrayArrayFunction(object):

@requires_array_function
def test_method(self):

class Other(object):
Expand Down Expand Up @@ -195,12 +202,13 @@ def test_no_wrapper(self):
# __array_function__ with invalid arguments, but check that we raise
# an appropriate error all the same.
array = np.array(1)
func = dispatched_one_arg._implementation
func = lambda x: x
with assert_raises_regex(AttributeError, '_implementation'):
array.__array_function__(func=func, types=(np.ndarray,),
args=(array,), kwargs={})


@requires_array_function
class TestArrayFunctionDispatch(object):

def test_pickle(self):
Expand Down Expand Up @@ -240,6 +248,7 @@ def __array_function__(self, func, types, args, kwargs):
dispatched_one_arg(array)


@requires_array_function
class TestVerifyMatchingSignatures(object):

def test_verify_matching_signatures(self):
Expand Down Expand Up @@ -292,6 +301,7 @@ def decorator(func):
return (MyArray, implements)


@requires_array_function
class TestArrayFunctionImplementation(object):

def test_one_arg(self):
Expand Down Expand Up @@ -372,6 +382,7 @@ def test_inspect_sum(self):
signature = inspect.signature(np.sum)
assert_('axis' in signature.parameters)

@requires_array_function
def test_override_sum(self):
MyArray, implements = _new_duck_type_and_implements()

Expand All @@ -381,6 +392,7 @@ def _(array):

assert_equal(np.sum(MyArray()), 'yes')

@requires_array_function
def test_sum_on_mock_array(self):

# We need a proxy for mocks because __array_function__ is only looked
Expand All @@ -401,6 +413,7 @@ def __array__(self, *args, **kwargs):
np.sum, (ArrayProxy,), (proxy,), {})
proxy.value.__array__.assert_not_called()

@requires_array_function
def test_sum_forwarding_implementation(self):

< 42D9 /span>
class MyArray(np.ndarray):
Expand Down
0