Repository: spyder-ide/spyder

Issue:
Error when trying to explore empty numpy array
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "/home/mybutt/miniconda2/lib/python2.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 449, in createEditor
    if not editor.setup_and_check(value, title=key, readonly=readonly):
  File "/home/mybutt/miniconda2/lib/python2.7/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 715, in setup_and_check
    self.current_dim_changed(self.last_dim)
  File "/home/mybutt/miniconda2/lib/python2.7/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 784, in current_dim_changed
    self.change_active_widget(0)
  File "/home/mybutt/miniconda2/lib/python2.7/site-packages/spyder/widgets/variableexplorer/arrayeditor.py", line 764, in change_active_widget
    self.data[slice_index]))
IndexError: index 0 is out of bounds for axis 0 with size 0


## Version and main components

* Spyder Version: 3.2.4 
* Python Version: 2.7.14
* Qt Versions: 5.6.2, PyQt5 5.6 on Linux

## Dependencies
```
pyflakes >=0.5.0  :  1.6.0 (OK)
pycodestyle >=2.3 :  2.3.1 (OK)
pygments >=2.0    :  2.2.0 (OK)
pandas >=0.13.1   :  0.20.3 (OK)
numpy >=1.7       :  1.13.3 (OK)
sphinx >=0.6.6    :  1.6.3 (OK)
rope >=0.9.4      :  0.10.5 (OK)
jedi >=0.9.0      :  0.10.2 (OK)
psutil >=0.3      :  5.4.0 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
sympy >=0.7.3     :  None (NOK)
cython >=0.21     :  None (NOK)
qtconsole >=4.2.0 :  4.3.1 (OK)
IPython >=4.0;<6.0:  5.4.1 (OK)
pylint >=0.25     :  1.7.4 (OK)

```



Discussion:
Thank you @Giangblackk. The variable `x` you created could not be visualized as it is empty. Its first dimension is 0, it has no element. With `x =np.zeros((1, 10, 20))` it works fine.  
@ccordoba12 should we add a check to not support the empty arrays?
@Prikers, we do support empty arrays, so we should catch this error and show an empty array editor instance.

Resolving patch:
diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py
--- a/spyder/widgets/variableexplorer/arrayeditor.py
+++ b/spyder/widgets/variableexplorer/arrayeditor.py
@@ -760,8 +760,11 @@ def change_active_widget(self, index):
         stack_index = self.dim_indexes[self.last_dim].get(data_index)
         if stack_index == None:
             stack_index = self.stack.count()
-            self.stack.addWidget(ArrayEditorWidget(self,
-                                                   self.data[slice_index]))
+            try:
+                self.stack.addWidget(ArrayEditorWidget(self,
+                                                       self.data[slice_index]))
+            except IndexError:  # Handle arrays of size 0 in one axis
+                self.stack.addWidget(ArrayEditorWidget(self, self.data))
             self.dim_indexes[self.last_dim][data_index] = stack_index
             self.stack.update()
         self.stack.setCurrentIndex(stack_index)


Test patch:
diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
--- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
+++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py
@@ -132,6 +132,13 @@ def test_arrayeditor_with_3d_array(qtbot):
     assert_array_equal(arr, launch_arrayeditor(arr, "3D array"))
 
 
+def test_arrayeditor_with_empty_3d_array(qtbot):
+    arr = np.zeros((0, 10, 2))
+    assert_array_equal(arr, launch_arrayeditor(arr, "3D array"))
+    arra = np.zeros((1, 10, 2))
+    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)