Skip to content

MAINT: Use exec() instead array_function_dispatch to improve tracebacks #13529

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 2 commits into from
May 13, 2019

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented May 11, 2019

xref GH-12028

Current behavior:

>>> np.dot(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 175, in public_api
    implementation, public_api, relevant_args, args, kwargs)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

>>> np.stack([], invalid=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 148, in public_api
    relevant_args = dispatcher(*args, **kwargs)
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'

With this change:

>>> np.dot(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 6, in dot
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

>>> np.stack([], invalid=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 4, in stack
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'

This fixes an issue pointed out by @mattip

xref numpyGH-12028

Current behavior:

>>> np.dot(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 175, in public_api
    implementation, public_api, relevant_args, args, kwargs)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

>>> np.stack([], invalid=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 148, in public_api
    relevant_args = dispatcher(*args, **kwargs)
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'

With this change:

>>> np.dot(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 6, in dot
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

>>> np.stack([], invalid=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 4, in stack
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'
@eric-wieser
Copy link
Member

Would be good to include your timing info in this PR for the sake of archaeology in future.

@shoyer
Copy link
Member Author

shoyer commented May 11, 2019

python -X importtime -c 'import numpy' will show import times. I ran this 100 times but could not identify a statistically significant difference in either the mean or min.

@charris charris merged commit 4ad33d2 into numpy:master May 13, 2019
@charris
Copy link
Member

charris commented May 13, 2019

Thanks Stephan.

@charris charris changed the title Use exec() instead array_function_dispatch to improve tracebacks MAINT: Use exec() instead array_function_dispatch to improve tracebacks May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants