Skip to content

Commit

Permalink
Make copy argument of __array__ method keyword-only
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-pavlyk committed Jan 14, 2025
1 parent f27d38f commit a9385af
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dpctl/tensor/_usmarray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,15 @@ cdef class usm_ndarray:
def __repr__(self):
return usm_ndarray_repr(self)

def __array__(self, dtype=None, copy=None):
"NumPy array protocol"
def __array__(self, dtype=None, /, *, copy=None):
"""NumPy's array protocol method to disallow implicit conversion.
Without this definition, `numpy.asarray(usm_ar)` converts
usm_ndarray instance into NumPy array with data type `object`
and every element being 0d usm_ndarray.
https://github.com/IntelPython/dpctl/pull/1384#issuecomment-1707212972
"""
raise TypeError(
"Implicit conversion to a NumPy array is not allowed. "
"Use `dpctl.tensor.asnumpy` to copy data from this "
Expand Down

0 comments on commit a9385af

Please sign in to comment.