data-apis / array-api-compat

Compatibility layer for common array libraries to support the Array API
https://data-apis.org/array-api-compat/
MIT License
69 stars 22 forks source link

BUG: `dask.array.asarray` cannot handle `int` input with `copy=True` #148

Closed lucascolley closed 2 months ago

lucascolley commented 2 months ago
In [1]: from scipy._lib.array_api_compat.dask import array as da

In [2]: da.asarray(1, copy=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 da.asarray(1, copy=True)

File ~/programming/scipy/build-install/lib/python3.12/site-packages/scipy/_lib/array_api_compat/common/_aliases.py:340, in _asarray(obj, dtype, device, copy, namespace, **kwargs)
    338 if copy in COPY_TRUE:
    339     if dtype is None:
--> 340         return obj.copy()
    341     # Go through numpy, since dask copy is no-op by default
    342     import numpy as np

AttributeError: 'int' object has no attribute 'copy'
asmeurer commented 2 months ago

This was already fixed in 1.6 https://data-apis.org/array-api-compat/changelog.html#id5

>>> array_api_compat.dask.array.asarray(1, copy=True)
dask.array<array, shape=(), dtype=int64, chunksize=(), chunktype=numpy.ndarray>
lucascolley commented 2 months ago

apologies, I thought we had the latest version checked out, thanks