Support assignment of DOK to DOK subarray
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Python
- Stars
- 668
- Forks
- 141
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 4
Description
Is your feature request related to a problem? Please describe.
Allow assignment of DOK subarray without requiring creation of dense array.
Describe the solution you'd like
>>> import sparse
>>> import numpy as np
>>> array = sparse.DOK([3,4,5], dtype=np.int8)
>>> subarray = sparse.DOK([4,5], dtype=np.int8)
>>> subarray[1,1] = 1
>>> array[0] = subarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/sparse/_dok.py", line 317, in __setitem__
value = np.asanyarray(value)
File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/numpy/core/_asarray.py", line 136, in asanyarray
return array(a, dtype, copy=False, order=order, subok=True)
File "/home/tyler/lib/anaconda3/envs/glia/lib/python3.8/site-packages/sparse/_sparse_array.py", line 222, in __array__
raise RuntimeError(
RuntimeError: Cannot convert a sparse array to dense automatically. To manually densify, use the todense method.
Describe alternatives you've considered
>>> array[0] = subarray.todense()
>>>
Additional context
If subarray is huge and very sparse, todense is not feasible.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DOK.setitem in sparse/_dok.py and the sparse-array conversion behavior in sparse/_sparse_array.py, using the issue's example to reproduce the failure. Done means assigning a sparse DOK subarray succeeds without implicitly converting it to a dense array; the issue does not mention a specific test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100