Repository: spyder-ide/spyder

Issue:
Exception if List contains array with only one element
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Run the following snippet:
```
import numpy as np
li = [np.array(5)]
```

click on `li` in variable explorer, click on type of included numpy array.

Exception is thrown

### Traceback
```python-traceback
Traceback (most recent call last):
  File "/home/maurer/gitea/spyder/spyder/widgets/collectionseditor.py", line 846, in refresh_menu
    is_array = self.is_array(key) and self.get_len(key) != 0
  File "/home/maurer/gitea/spyder/spyder/widgets/collectionseditor.py", line 1349, in get_len
    return len(data[key])
TypeError: len() of unsized object
```

## Versions

* Spyder version: 5.5.0.dev0 12a6bdf31 (conda)
* Python version: 3.10.8 64-bit
* Qt version: 5.15.2
* PyQt5 version: 5.15.7
* Operating System: Linux 5.10.0-19-amd64

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0          :  1.4.1 (OK)
chardet >=2.0.0               :  5.0.0 (OK)
cloudpickle >=0.5.0           :  2.2.0 (OK)
cookiecutter >=1.6.0          :  2.1.1 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.31.1;<8.0.0       :  7.34.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.17.0 (OK)
keyring >=17.0.0              :  23.11.0 (OK)
nbconvert >=4.0               :  7.2.5 (OK)
numpydoc >=0.6.0              :  1.5.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.4 (OK)
pygments >=2.0                :  2.13.0 (OK)
pylint >=2.5.0;<3.0           :  2.15.6 (OK)
pylint_venv >=2.1.1           :  2.3.0 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.6.0;<1.7.0          :  1.6.0 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.3 (OK)
qstylizer >=0.2.2             :  0.2.2 (OK)
qtawesome >=1.2.1             :  1.2.1 (OK)
qtconsole >=5.4.0;<5.5.0      :  5.5.0.dev0 (OK)
qtpy >=2.1.0                  :  2.3.0 (OK)
rtree >=0.9.7                 :  1.0.1 (OK)
setuptools >=49.6.0           :  65.5.0 (OK)
sphinx >=0.6.6                :  5.3.0 (OK)
spyder_kernels >=2.4.0;<2.5.0 :  2.5.0.dev0 (OK)
textdistance >=4.2.0          :  4.5.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.9 (OK)
xdg >=0.26                    :  0.28 (OK)
zmq >=22.1.0                  :  24.0.1 (OK)

# Optional:
cython >=0.21                 :  0.29.32 (OK)
matplotlib >=3.0.0            :  3.6.2 (OK)
numpy >=1.7                   :  1.23.4 (OK)
pandas >=1.1.1                :  1.5.1 (OK)
scipy >=0.17.0                :  1.9.3 (OK)
sympy >=0.7.3                 :  1.11.1 (OK)
```



Discussion:
Thanks @maurerle for the feedback! I was able to reproduce this :+1:

I think we need to add a validation to the `get_len` to properly manage the numpy arrays. Maybe something like:

```python
def get_len(self, key):
        """Return sequence length"""
        data = self.source_model.get_data()
        if self.is_array(key):
            return self.get_array_ndim(key)
        else:
            return len(data[key])
```

Let us know if you want to help with this!

Resolving patch:
diff --git a/spyder/widgets/collectionseditor.py b/spyder/widgets/collectionseditor.py
--- a/spyder/widgets/collectionseditor.py
+++ b/spyder/widgets/collectionseditor.py
@@ -1346,7 +1346,10 @@ def is_set(self, key):
     def get_len(self, key):
         """Return sequence length"""
         data = self.source_model.get_data()
-        return len(data[key])
+        if self.is_array(key):
+            return self.get_array_ndim(key)
+        else:
+            return len(data[key])
 
     def is_array(self, key):
         """Return True if variable is a numpy array"""


Test patch: