Repository: spyder-ide/spyder

Issue:
BUG: Error editing element of numpy array in variable explorer
## Description

**What steps will reproduce the problem?**
1. Enter the following in the editor
```python
import numpy as np
b = np.arange(4)
```

2. Open `b` in variable explorer

3. Double click on the first element and change it from 0 to 5

4. Click OK

5. Got this error report pop up

  File "/Users/measejm1/anaconda/envs/python3_general/lib/python3.6/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 384, in setEditorData
    text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
  File "/Users/measejm1/anaconda/envs/python3_general/lib/python3.6/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 253, in data
    value = self.get_value(index)
  File "/Users/measejm1/anaconda/envs/python3_general/lib/python3.6/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 247, in get_value
    return self.changes.get((i, j), self._data[i, j])
IndexError: too many indices for array

**What is the expected output? What do you see instead?**
Expected the first element to be changed to 5 in the workspace

## Version and main components

* Spyder Version: 3.2.1 
* Python Version: 3.6.0
* Qt Versions: 5.6.2, PyQt5 5.6 on Darwin

## Dependencies
```
pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.1.3 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.12.1 (OK)
sphinx >=0.6.6   :  1.5.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
psutil >=0.3     :  5.0.1 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.6.4 (OK)

```



Discussion:
@andfoy, please take a look at this one. I think it only happens with 1D Numpy arrays.

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py
--- a/spyder/widgets/variableexplorer/arrayeditor.py
+++ b/spyder/widgets/variableexplorer/arrayeditor.py
@@ -244,7 +244,11 @@ def bgcolor(self, state):
     def get_value(self, index):
         i = index.row()
         j = index.column()
-        return self.changes.get((i, j), self._data[i, j])
+        if len(self._data.shape) == 1:
+            value = self._data[j]
+        else:
+            value = self._data[i, j]
+        return self.changes.get((i, j), value)
 
     def data(self, index, role=Qt.DisplayRole):
         """Cell content"""


Test patch:
diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
--- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
+++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
@@ -120,6 +120,45 @@ def test_arrayeditor_with_3d_array(qtbot):
     assert_array_equal(arr, launch_arrayeditor(arr, "3D array"))
 
 
+def test_arrayeditor_edit_1d_array(qtbot):
+    exp_arr = np.array([1, 0, 2, 3, 4])
+    arr = np.arange(0, 5)
+    dlg = ArrayEditor()
+    assert dlg.setup_and_check(arr, '1D array', xlabels=None, ylabels=None)
+    dlg.show()
+    qtbot.waitForWindowShown(dlg)
+    view = dlg.arraywidget.view
+
+    qtbot.keyPress(view, Qt.Key_Down)
+    qtbot.keyPress(view, Qt.Key_Up)
+    qtbot.keyClicks(view, '1')
+    qtbot.keyPress(view, Qt.Key_Down)
+    qtbot.keyClicks(view, '0')
+    qtbot.keyPress(view, Qt.Key_Down)
+    qtbot.keyPress(view, Qt.Key_Return)
+    assert np.sum(exp_arr == dlg.get_value()) == 5
+
+
+def test_arrayeditor_edit_2d_array(qtbot):
+    arr = np.ones((3, 3))
+    diff_arr = arr.copy()
+    dlg = ArrayEditor()
+    assert dlg.setup_and_check(arr, '2D array', xlabels=None, ylabels=None)
+    dlg.show()
+    qtbot.waitForWindowShown(dlg)
+    view = dlg.arraywidget.view
+
+    qtbot.keyPress(view, Qt.Key_Down)
+    qtbot.keyPress(view, Qt.Key_Right)
+    qtbot.keyClicks(view, '3')
+    qtbot.keyPress(view, Qt.Key_Down)
+    qtbot.keyPress(view, Qt.Key_Right)
+    qtbot.keyClicks(view, '0')
+    qtbot.keyPress(view, Qt.Key_Left)
+    qtbot.keyPress(view, Qt.Key_Return)
+
+    assert np.sum(diff_arr != dlg.get_value()) == 2
+
+
 if __name__ == "__main__":
     pytest.main()
-