Repository: spyder-ide/spyder

Issue:
Variable editor problems on clicking
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

When I double click on a complex variable in a 40x40 complex double array in the variable editor, this problem occured.

### Traceback
```python-traceback
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\arrayeditor.py", line 331, in setData
    if val < self.vmin:
TypeError: '<' not supported between instances of 'float' and 'complex'
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 401, 'json': {'message': 'Bad credentials', 'documentation_url': 'https://developer.github.com/v3'}}
```

## Versions

* Spyder version: 3.3.0 
* Python version: 3.6.5
* Qt version: 5.9.4
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
pyflakes >=0.6.0  :  1.6.0 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
sphinx >=0.6.6    :  1.7.2 (OK)
rope >=0.9.4      :  0.10.7 (OK)
jedi >=0.9.0      :  0.12.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
pandas >=0.13.1   :  0.22.0 (OK)
numpy >=1.7       :  1.14.2 (OK)
sympy >=0.7.3     :  1.1.1 (OK)
cython >=0.21     :  0.28.2 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0     :  6.3.1 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
pylint >=0.25     :  1.8.4 (OK)
```



Discussion:
Thanks for reporting. Please post the code you used to generate the array you mentioned, so we can reproduce this error in our side.
Thanks for the reply, Carlos!
I created a minimum working example here. I think the error could be due to the coloring of complex128 2-D arrays with postive as well as negative values. To reproduce the error, 
1. Run this on Sypder in an editor window. 
2. Go to the variable explorer, double click on the variable 'a'.
3. In  the dialog that opens, double click on a positive value and then  a negative value. The coloring of the whole dialog changes, and an error prompt to report to GitHub is raised (either directly or after double clicking again).

```
import numpy as np

a = (np.random.random((10, 10)) - 0.50) * (1+0.5j)
```

Please keep up the great work - I enjoy using Spyder and hope to see it getting better, with 4.0 esp/code folding. 
Thanks for the reproducible example. We'll take a look at this in a future release.

Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/arrayeditor.py b/spyder/plugins/variableexplorer/widgets/arrayeditor.py
--- a/spyder/plugins/variableexplorer/widgets/arrayeditor.py
+++ b/spyder/plugins/variableexplorer/widgets/arrayeditor.py
@@ -346,11 +346,16 @@ def setData(self, index, value, role=Qt.EditRole):
         # Add change to self.changes
         self.changes[(i, j)] = val
         self.dataChanged.emit(index, index)
+
         if not is_string(val):
+            val = self.color_func(val)
+
             if val > self.vmax:
                 self.vmax = val
+
             if val < self.vmin:
                 self.vmin = val
+
         return True
 
     def flags(self, index):
@@ -854,10 +859,15 @@ def current_dim_changed(self, index):
 
     @Slot()
     def accept(self):
-        """Reimplement Qt method"""
-        for index in range(self.stack.count()):
-            self.stack.widget(index).accept_changes()
-        QDialog.accept(self)
+        """Reimplement Qt method."""
+        try:
+            for index in range(self.stack.count()):
+                self.stack.widget(index).accept_changes()
+            QDialog.accept(self)
+        except RuntimeError:
+            # Sometimes under CI testing the object the following error appears
+            # RuntimeError: wrapped C/C++ object has been deleted
+            pass
 
     def get_value(self):
         """Return modified array -- this is *not* a copy"""


Test patch:
diff --git a/spyder/plugins/variableexplorer/widgets/tests/test_arrayeditor.py b/spyder/plugins/variableexplorer/widgets/tests/test_arrayeditor.py
--- a/spyder/plugins/variableexplorer/widgets/tests/test_arrayeditor.py
+++ b/spyder/plugins/variableexplorer/widgets/tests/test_arrayeditor.py
@@ -221,6 +221,28 @@ def test_arrayeditor_edit_2d_array(qtbot):
     assert np.sum(diff_arr != dlg.get_value()) == 2
 
 
+def test_arrayeditor_edit_complex_array(qtbot):
+    """See: spyder-ide/spyder#7848"""
+    cnum = -1+0.5j
+    arr = (np.random.random((10, 10)) - 0.50) * cnum
+    dlg = ArrayEditor()
+    assert dlg.setup_and_check(arr, '2D complex array', xlabels=None,
+                               ylabels=None)
+    dlg.show()
+    qtbot.waitForWindowShown(dlg)
+    view = dlg.arraywidget.view
+    qtbot.keyPress(view, Qt.Key_Down)
+
+    # Prevent the test from failing
+    qtbot.wait(300)
+
+    # This is the actual editor widget on the cell
+    cell_editor = view.viewport().focusWidget()
+    qtbot.keyClicks(cell_editor, str(cnum))
+    qtbot.keyPress(cell_editor, Qt.Key_Return)
+    dlg.accept()
+
+
 def test_arraymodel_set_data_overflow(monkeypatch):
     """
     Test that entry of an overflowing integer is caught and handled properly.