mars-project / mars-project/mars
[BUG] Inconsistency of __setitem__ with numpy
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The behavior is inconsistent with numpy.
**To Reproduce**
To help us reproducing this bug, please provide information below:
1. Your Python version: python 3.7
2. The version of Mars you use: master
3. Versions of crucial packages, such as numpy, scipy and protobuf
4. Full stack of the error.
```
Traceback (most recent call last):
File "", line 1, in
File "/Users/hetao/mars/mars/tensor/expressions/indexing/setitem.py", line 113, in _setitem
value = broadcast_to(value, shape).astype(a.dtype)
File "/Users/hetao/mars/mars/tensor/expressions/base/broadcast_to.py", line 103, in broadcast_to
raise ValueError('input operand has more dimensions than allowed by the axis remapping')
ValueError: input operand has more dimensions than allowed by the axis remapping
>>>
```
5. Minimized code to reproduce the error.
```python
import numpy as np
import mars.tensor as mt
x = np.zeros((4, 4))
x[1] = np.array([[1,2,3,4]]) # works
x = mt.zeros((4, 4))
x[1] = np.array([[1,2,3,4]]) # raise an exception
```
**Expected behavior**
The behavior should be consistent with numpy. The value `np.array([[1,2,3,4]])` should be firstly `broadcast_to` as `[1, 4]`, then `reshape` it as `[4]`.
**Additional context**
Add any other context about the problem here.
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 mars/tensor/expressions/indexing/setitem.py and trace its call to mars/tensor/expressions/base/broadcast_to.py. Run the provided NumPy and Mars reproducer, then verify that the Mars assignment accepts the [1, 4] value and produces the same result as NumPy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100