Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion array_api_compat/common/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,14 @@ def is_array_api_obj(x: object) -> TypeGuard[_ArrayApiObj]:
is_dask_array
is_jax_array
"""
try:
# TODO: drop this check after np.matrix is gone
if _issubclass_fast(type(x), "numpy", "matrix"):
return False
except Exception:
pass
return (
hasattr(x, '__array_namespace__')
hasattr(x, '__array_namespace__')
or _is_array_api_cls(cast(Hashable, type(x)))
)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Test "unspecified" behavior which we cannot easily test in the Array API test suite.
"""
import warnings
import pytest

try:
import numpy as np
except ImportError:
pytestmark = pytest.skip(allow_module_level=True, reason="numpy not found")

from array_api_compat import is_array_api_obj

def test_matrix_is_not_array_api_obj():
assert is_array_api_obj(np.asarray(3))
assert is_array_api_obj(np.float64(3))

with warnings.catch_warnings():
warnings.simplefilter("ignore", PendingDeprecationWarning)
assert not is_array_api_obj(np.matrix(3))
Comment thread
ev-br marked this conversation as resolved.
Loading