Repository: spyder-ide/spyder

Issue:
Unable to see Float16 in Spyder Variable Explorer
## Description of your problem

**What steps will reproduce the problem?**
1. v= np.zeros((5,5), dtype=np.float16)
2.   In  Variable click on v to see inside the table, an Error saying Float16 is not supported.

**What is the expected output? What do you see instead?**
We can see Float32 and Float64,  Float16 is useful, especially
for neural network (Google even uses Float8 .... !!)

Able to see Float16, Float8 in Variable Explorer.
## Versions and main components
- Spyder Version:  Spyder 2.3.5.2 
- Python Version: Python 2.7.10 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Windows
- Operating system:  Windows 7
## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:



Discussion:
@arita37 thanks for your report. Your Spyder is a bit out of date: the latest stable version is 2.3.9, but the issue still persists in that version. We should be able to add support for float16. However, I can't find anything about float8; is there any documentation about this type?

Hello,

Am using WinPython.
Is there a way to update Spyder without messing all my installed package in WinPython ?

Thanks

On 22 Jun 2016, at 17:47, Jitse Niesen notifications@github.com wrote:

@arita37 thanks for your report. Your Spyder is a bit out of date: the latest stable version is 2.3.9, but the issue still persists in that version. We should be able to add support for float16. However, I can't find anything about float8; is there any documentation about this type?

―
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@jitseniesen, we define our list of supported types for the Variable Explorer:

https://github.com/spyder-ide/spyder/blob/master/spyderlib/config/base.py#L343

I think you shouldn't have much problem in adding and testing that we can show `float16` arrays too :-)

> Am using WinPython. Is there a way to update Spyder without messing all my installed package in WinPython ?

I'm not using WinPython so I don't know. @stonebig do you know?

I woud try:
- copy/paste Winpython directory (the winpython-copy is a backup, if all goes wrong, ziping it would do also)
- start "Winpython Command Prompt", and

```
python -m pip install --upgrade pip
%WINPYDIR%\..\scripts\make_winpython_movable.bat
```

then

```
pip install qtpy
```

```
pip uninstall spyder
```

(answer `y` to the question)
then

```
pip install spyder
```

nota:
- WinPython2.7 is no longer maintained, so it's theorical suggestion
- you will install that way spyder 2.3.9.
- I did experiment it on an old 2.710 beta, not sure it would work on official one


Resolving patch:
diff --git a/spyderlib/widgets/variableexplorer/arrayeditor.py b/spyderlib/widgets/variableexplorer/arrayeditor.py
--- a/spyderlib/widgets/variableexplorer/arrayeditor.py
+++ b/spyderlib/widgets/variableexplorer/arrayeditor.py
@@ -37,8 +37,7 @@
                                  is_text_string, PY3, to_binary_string,
                                  to_text_string)
 from spyderlib.utils import icon_manager as ima
-from spyderlib.utils.qthelpers import (add_actions, create_action, keybinding,
-                                       qapplication)
+from spyderlib.utils.qthelpers import add_actions, create_action, keybinding
 
 
 # Note: string and unicode data types will be formatted with '%s' (see below)
@@ -47,6 +46,7 @@
                      'double': '%.3f',
                      'float_': '%.3f',
                      'longfloat': '%.3f',
+                     'float16': '%.3f',
                      'float32': '%.3f',
                      'float64': '%.3f',
                      'float96': '%.3f',
@@ -797,71 +797,3 @@ def reject(self):
             for index in range(self.stack.count()):
                 self.stack.widget(index).reject_changes()
         QDialog.reject(self)
-
-
-#==============================================================================
-# Tests
-#==============================================================================    
-def test_edit(data, title="", xlabels=None, ylabels=None,
-              readonly=False, parent=None):
-    """Test subroutine"""
-    app = qapplication(test_time=1.5)    # analysis:ignore
-    dlg = ArrayEditor(parent)
-
-    if dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels,
-                           readonly=readonly):
-        dlg.exec_()
-        return dlg.get_value()
-    else:
-        import sys
-        sys.exit(1)
-
-
-def test():
-    """Array editor test"""
-    from numpy.testing import assert_array_equal
-
-    arr = np.array(["kjrekrjkejr"])
-    assert arr == test_edit(arr, "string array")
-
-    arr = np.array([u"ñññéáíó"])
-    assert arr == test_edit(arr, "unicode array")
-
-    arr = np.ma.array([[1, 0], [1, 0]], mask=[[True, False], [False, False]])
-    assert_array_equal(arr, test_edit(arr, "masked array"))
-
-    arr = np.zeros((2, 2), {'names': ('red', 'green', 'blue'),
-                           'formats': (np.float32, np.float32, np.float32)})
-    assert_array_equal(arr, test_edit(arr, "record array"))
-
-    arr = np.array([(0, 0.0), (0, 0.0), (0, 0.0)],
-                   dtype=[(('title 1', 'x'), '|i1'),
-                          (('title 2', 'y'), '>f4')])
-    assert_array_equal(arr, test_edit(arr, "record array with titles"))
-
-    arr = np.random.rand(5, 5)
-    assert_array_equal(arr, test_edit(arr, "float array",
-                                      xlabels=['a', 'b', 'c', 'd', 'e']))
-
-    arr = np.round(np.random.rand(5, 5)*10)+\
-                   np.round(np.random.rand(5, 5)*10)*1j
-    assert_array_equal(arr, test_edit(arr, "complex array",
-                                      xlabels=np.linspace(-12, 12, 5),
-                                      ylabels=np.linspace(-12, 12, 5)))
-
-    arr_in = np.array([True, False, True])
-    arr_out = test_edit(arr_in, "bool array")
-    assert arr_in is arr_out
-
-    arr = np.array([1, 2, 3], dtype="int8")
-    assert_array_equal(arr, test_edit(arr, "int array"))
-
-    arr = np.zeros((3,3,4))
-    arr[0,0,0]=1
-    arr[0,0,1]=2
-    arr[0,0,2]=3
-    assert_array_equal(arr, test_edit(arr, "3D array"))
-
-
-if __name__ == "__main__":
-    test()


Test patch:
diff --git a/spyderlib/widgets/variableexplorer/tests/test_arrayeditor.py b/spyderlib/widgets/variableexplorer/tests/test_arrayeditor.py
new file mode 100644
--- /dev/null
+++ b/spyderlib/widgets/variableexplorer/tests/test_arrayeditor.py
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2009- The Spyder Development Team
+# Licensed under the terms of the MIT License
+
+"""
+Tests for arrayeditor.py
+"""
+
+# Third party imports
+import numpy as np
+from numpy.testing import assert_array_equal
+import pytest
+
+# Local imports
+from spyderlib.utils.qthelpers import qapplication
+from spyderlib.widgets.variableexplorer.arrayeditor import ArrayEditor
+
+
+def launch_arrayeditor(data, title="", xlabels=None, ylabels=None):
+    """Helper routine to launch an arrayeditor and return its result"""
+    dlg = ArrayEditor()
+    assert dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)
+    dlg.show()
+    dlg.accept()  # trigger slot connected to OK button
+    return dlg.get_value()
+
+
+# --- Tests
+# -----------------------------------------------------------------------------
+def test_arrayeditor_with_string_array(qtbot):
+    arr = np.array(["kjrekrjkejr"])
+    assert arr == launch_arrayeditor(arr, "string array")
+
+def test_arrayeditor_with_unicode_array(qtbot):
+    arr = np.array([u"ñññéáíó"])
+    assert arr == launch_arrayeditor(arr, "unicode array")
+
+def test_arrayeditor_with_masked_array(qtbot):
+    arr = np.ma.array([[1, 0], [1, 0]], mask=[[True, False], [False, False]])
+    assert_array_equal(arr, launch_arrayeditor(arr, "masked array"))
+
+def test_arrayeditor_with_record_array(qtbot):
+    arr = np.zeros((2, 2), {'names': ('red', 'green', 'blue'),
+                           'formats': (np.float32, np.float32, np.float32)})
+    assert_array_equal(arr, launch_arrayeditor(arr, "record array"))
+
+def test_arrayeditor_with_record_array_with_titles(qtbot):
+    arr = np.array([(0, 0.0), (0, 0.0), (0, 0.0)],
+                   dtype=[(('title 1', 'x'), '|i1'),
+                          (('title 2', 'y'), '>f4')])
+    assert_array_equal(arr, launch_arrayeditor(arr, "record array with titles"))
+
+def test_arrayeditor_with_float_array(qtbot):
+    arr = np.random.rand(5, 5)
+    assert_array_equal(arr, launch_arrayeditor(arr, "float array",
+                                      xlabels=['a', 'b', 'c', 'd', 'e']))
+
+def test_arrayeditor_with_complex_array(qtbot):
+    arr = np.round(np.random.rand(5, 5)*10)+\
+                   np.round(np.random.rand(5, 5)*10)*1j
+    assert_array_equal(arr, launch_arrayeditor(arr, "complex array",
+                                      xlabels=np.linspace(-12, 12, 5),
+                                      ylabels=np.linspace(-12, 12, 5)))
+
+def test_arrayeditor_with_bool_array(qtbot):
+    arr_in = np.array([True, False, True])
+    arr_out = launch_arrayeditor(arr_in, "bool array")
+    assert arr_in is arr_out
+
+def test_arrayeditor_with_int8_array(qtbot):
+    arr = np.array([1, 2, 3], dtype="int8")
+    assert_array_equal(arr, launch_arrayeditor(arr, "int array"))
+
+def test_arrayeditor_with_float16_array(qtbot):
+    arr = np.zeros((5,5), dtype=np.float16)
+    assert_array_equal(arr, launch_arrayeditor(arr, "float16 array"))
+
+def test_arrayeditor_with_3d_array(qtbot):
+    arr = np.zeros((3,3,4))
+    arr[0,0,0]=1
+    arr[0,0,1]=2
+    arr[0,0,2]=3
+    assert_array_equal(arr, launch_arrayeditor(arr, "3D array"))
+
+
+if __name__ == "__main__":
+    pytest.main()
+