From 4f4f4f49741d7ae866af0555280fff2a421eb6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 25 Aug 2017 17:41:43 -0500 Subject: [PATCH 1/4] Fix 1D numpy arrays edition issue --- spyder/widgets/variableexplorer/arrayeditor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py index 9ec78036836..c50cfe06930 100644 --- 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""" From aba56e57ba6389969d91f12ee845e6563e11abe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 25 Aug 2017 19:03:09 -0500 Subject: [PATCH 2/4] Tests added --- .../tests/test_arrayeditor.py | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index 173f9d7ef71..126d8955a0a 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -120,6 +120,47 @@ 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.random.rand(3, 3) + exp_arr = arr.copy() + exp_arr[1, 1] = 3 + exp_arr[2, 2] = 0 + 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_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(exp_arr == dlg.get_value()) == 9 + + if __name__ == "__main__": pytest.main() - From da2936419c0a368344b01d60dda72eefe4b98fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 25 Aug 2017 19:20:53 -0500 Subject: [PATCH 3/4] 2D: Initialize with ones --- spyder/widgets/variableexplorer/tests/test_arrayeditor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index 126d8955a0a..56963a832e0 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -140,12 +140,12 @@ def test_arrayeditor_edit_1d_array(qtbot): def test_arrayeditor_edit_2d_array(qtbot): - arr = np.random.rand(3, 3) + arr = np.ones((3, 3)) exp_arr = arr.copy() exp_arr[1, 1] = 3 exp_arr[2, 2] = 0 dlg = ArrayEditor() - assert dlg.setup_and_check(arr, '1D array', xlabels=None, ylabels=None) + assert dlg.setup_and_check(arr, '2D array', xlabels=None, ylabels=None) dlg.show() qtbot.waitForWindowShown(dlg) view = dlg.arraywidget.view From ef843166db651e41783202580ab02bed8cc00008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Fri, 25 Aug 2017 19:42:22 -0500 Subject: [PATCH 4/4] 2D: Simplify test numeric comparison --- spyder/widgets/variableexplorer/tests/test_arrayeditor.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index 56963a832e0..a2f19e7329c 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -141,9 +141,7 @@ def test_arrayeditor_edit_1d_array(qtbot): def test_arrayeditor_edit_2d_array(qtbot): arr = np.ones((3, 3)) - exp_arr = arr.copy() - exp_arr[1, 1] = 3 - exp_arr[2, 2] = 0 + diff_arr = arr.copy() dlg = ArrayEditor() assert dlg.setup_and_check(arr, '2D array', xlabels=None, ylabels=None) dlg.show() @@ -159,7 +157,7 @@ def test_arrayeditor_edit_2d_array(qtbot): qtbot.keyPress(view, Qt.Key_Left) qtbot.keyPress(view, Qt.Key_Return) - assert np.sum(exp_arr == dlg.get_value()) == 9 + assert np.sum(diff_arr != dlg.get_value()) == 2 if __name__ == "__main__":