-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🐛 compatibility issues with ArrayAPI and SparseAPI Protocols in namedarray
#8696
Comments
Note that on python 3.12 and higher this will actually start to work because it will not use See also #8605 |
Isn't this a bug in sparse? import numpy as np
import numpy.array_api as xp
import sparse
a_np = np.array(['a', 'b']).astype(object)
a_sparse = sparse.COO(a_np)
print(a_np.real) # works
print(a_sparse.real) # ValueError: invalid literal for int() with base 10: 'a'
a_xp = xp.asarray(a_np) # TypeError: The array_api namespace does not support the dtype 'object'
Lines 262 to 273 in c9ba2be
It is simply not true that namedarray only needs these for everything to work as namedarray use .real , .imag etc.The true minimum requirement is _arrayfunction_or_api .
By using |
What happened?
i'm experiencing compatibility issues when using
_arrayfunction_or_api
and_sparsearrayfunction_or_api
with the sparse arrays withdtype=object
. specifically, runtime checks usingisinstance
with these protocols are failing, despite the sparse array object appearing to meet the necessary criteria (attributes and methods).What did you expect to happen?
i expected that since COO arrays from the sparse library provide the necessary attributes and methods, they would pass the
isinstance
checks with the defined protocols.the failing case appears to be a well know issue
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
i was trying to replace instances of
is_duck_array
with the protocol runtime checks (as part of #8319), and i've come to a realization that these runtime checks are rigid to accommodate the diverse behaviors of different array types, andis_duck_array()
the function-based approach might be more manageable.@Illviljan, are there any changes that could be made to both protocols without making them too complex?
Environment
The text was updated successfully, but these errors were encountered: