Skip to content

Commit

Permalink
Merge from 3.x: PR #5064
Browse files Browse the repository at this point in the history
Fixes #5014
  • Loading branch information
ccordoba12 committed Aug 26, 2017
2 parents 03b129e + a6200ae commit aa77662
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
6 changes: 5 additions & 1 deletion spyder/widgets/variableexplorer/arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
41 changes: 40 additions & 1 deletion spyder/widgets/variableexplorer/tests/test_arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit aa77662

Please sign in to comment.