Repository: spyder-ide/spyder

Issue:
Loadmat internal error in variable explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Loaded a .mat file with:
from scipy.io import loadmat
data= loadmat('filename.mat')

The data was successfully loaded.
If I open "filename.mat" with matlab, I have a "S" (1x1 struct). "S" contains 23 fields.

When I load it with python in Spyder with the above code, "data" is a dictionary that has a key called "S" (with type: Array of Void1472, size: (1,1), value: ndarray of numpy module ). When I double click on "data" in the variable explorer, and then double click on "S" wanting to see the subvariables (fields in matlab= subarrays) under "S" the internal error message shows up.




### Traceback
```python-traceback
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 138, in createEditor
    if not editor.setup_and_check(value, title=key, readonly=readonly):
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 699, in setup_and_check
    ylabels))
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 568, in __init__
    ylabels=ylabels, readonly=readonly, parent=self)
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 156, in __init__
    self.vmin = np.nanmin(self.color_func(data))
  File "<__array_function__ internals>", line 6, in nanmin
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 334, in nanmin
    res = _copyto(res, np.nan, mask)
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 139, in _copyto
    a = a.dtype.type(val)
AttributeError: 'float' object has no attribute 'dtype'
Traceback (most recent call last):
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/collectionsdelegate.py", line 138, in createEditor
    if not editor.setup_and_check(value, title=key, readonly=readonly):
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 699, in setup_and_check
    ylabels))
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 568, in __init__
    ylabels=ylabels, readonly=readonly, parent=self)
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/spyder/plugins/variableexplorer/widgets/arrayeditor.py", line 156, in __init__
    self.vmin = np.nanmin(self.color_func(data))
  File "<__array_function__ internals>", line 6, in nanmin
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 334, in nanmin
    res = _copyto(res, np.nan, mask)
  File "/Users/hilaryc/opt/anaconda3/envs/seis/lib/python3.7/site-packages/numpy/lib/nanfunctions.py", line 139, in _copyto
    a = a.dtype.type(val)
AttributeError: 'float' object has no attribute 'dtype'
```

## Versions

* Spyder version: 4.0.0 
* Python version: 3.7.3
* Qt version: 5.12.5
* PyQt5 version: 5.12.3
* Operating System: Darwin 19.2.0

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.5.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.3.1 (OK)
pylint >=0.25                :  2.4.4 (OK)
psutil >=0.3                 :  5.6.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.1 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.5 (OK)
cython >=0.21                :  0.29.14 (OK)
IPython >=4.0                :  7.11.1 (OK)
matplotlib >=2.0.0           :  3.1.2 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
numpy >=1.7                  :  1.17.4 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.4 (OK)
applaunchservices >=0.1.7    :  0.2.1 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
```



Discussion:
Please upload `filename.mat` so we can reproduce this problem in our side.
> Please upload `filename.mat` so we can reproduce this problem in our side.


[Vibroseis_segy_timingLog_PoroTomo_Mar2016_Phases_1234_wUTM_wDateTime_v5.mat.zip](https://github.com/spyder-ide/spyder/files/4021219/Vibroseis_segy_timingLog_PoroTomo_Mar2016_Phases_1234_wUTM_wDateTime_v5.mat.zip)

@dalthviz, please test if you can reproduce this one.
@ccordoba12 I can reproduce this:

![image](https://user-images.githubusercontent.com/16781833/71826177-57bf2500-306b-11ea-8ee2-37dcd19d0741.png)


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
@@ -160,7 +160,7 @@ def __init__(self, data, format="%.6g", xlabels=None, ylabels=None,
             self.hue0 = huerange[0]
             self.dhue = huerange[1]-huerange[0]
             self.bgcolor_enabled = True
-        except (TypeError, ValueError):
+        except (AttributeError, TypeError, ValueError):
             self.vmin = None
             self.vmax = None
             self.hue0 = None


Test patch:
diff --git a/spyder/plugins/variableexplorer/widgets/tests/issue_11216.mat b/spyder/plugins/variableexplorer/widgets/tests/issue_11216.mat
new file mode 100644
Binary files /dev/null and b/spyder/plugins/variableexplorer/widgets/tests/issue_11216.mat differ
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
@@ -29,6 +29,12 @@
 from spyder.plugins.variableexplorer.widgets.arrayeditor import ArrayEditor, ArrayModel
 
 
+# =============================================================================
+# Constants
+# =============================================================================
+HERE = os.path.dirname(os.path.realpath(__file__))
+
+
 # =============================================================================
 # Utility functions
 # =============================================================================
@@ -70,6 +76,18 @@ def test_object_arrays_display(qtbot):
     assert u'[Numpy array]' == dlg.arraywidget.model.data(idx)
 
 
+def test_attribute_errors(qtbot):
+    """
+    Verify that we don't get a AttributeError for certain structured arrays.
+
+    Fixes spyder-ide/spyder#11216 .
+    """
+    from scipy.io import loadmat
+    data = loadmat(os.path.join(HERE, 'issue_11216.mat'))
+    dlg = setup_arrayeditor(qtbot, data['S'])
+    contents = dlg.arraywidget.model.get_value(dlg.arraywidget.model.index(0, 0))
+    assert_array_equal(contents, data['S'][0][0][0])
+
 def test_type_errors(qtbot):
     """
     Verify that we don't get a TypeError for certain structured arrays.