Skip to content

ENH: disallow passing array-like to array_namespace #42

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
Dec 11, 2023
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
4 changes: 1 addition & 3 deletions array_api_compat/common/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def your_function(x, y):
"""
namespaces = set()
for x in xs:
if isinstance(x, (tuple, list)):
namespaces.add(array_namespace(*x, _use_compat=_use_compat))
elif hasattr(x, '__array_namespace__'):
if hasattr(x, '__array_namespace__'):
namespaces.add(x.__array_namespace__(api_version=api_version))
elif _is_numpy_array(x):
_check_api_version(api_version)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_array_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ def test_array_namespace(library, api_version):
else:
assert namespace == getattr(array_api_compat, library)

def test_array_namespace_multiple():
import numpy as np

x = np.asarray([1, 2])
assert array_namespace(x, x) == array_namespace((x, x)) == \
array_namespace((x, x), x) == array_api_compat.numpy

def test_array_namespace_errors():
pytest.raises(TypeError, lambda: array_namespace([1]))
pytest.raises(TypeError, lambda: array_namespace([1, 2]))
pytest.raises(TypeError, lambda: array_namespace())

import numpy as np
Expand Down