Bugfixes for displaying numpy arrays.

Wed, 06 Nov 2019 22:30:54 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Wed, 06 Nov 2019 22:30:54 +0100
changeset 7332
49076c600903
parent 7331
1fb70d1f8a39
child 7333
8479201bdf7b

Bugfixes for displaying numpy arrays.

eric6/DebugClients/Python/DebugVariables.py file | annotate | diff | comparison | revisions
eric6/Debugger/VariablesViewer.py file | annotate | diff | comparison | revisions
--- a/eric6/DebugClients/Python/DebugVariables.py	Wed Nov 06 18:35:11 2019 +0100
+++ b/eric6/DebugClients/Python/DebugVariables.py	Wed Nov 06 22:30:54 2019 +0100
@@ -414,7 +414,11 @@
         """
         d = {}
         start = count = 0
-        allItems = var.tolist()
+        try:
+            len(var)  # Check if it's an unsized object, e.g. np.ndarray(())
+            allItems = var.tolist()
+        except TypeError:  # TypeError: len() of unsized object
+            allItems = []
         
         for idx, value in enumerate(allItems):
             d[str(idx)] = value
--- a/eric6/Debugger/VariablesViewer.py	Wed Nov 06 18:35:11 2019 +0100
+++ b/eric6/Debugger/VariablesViewer.py	Wed Nov 06 22:30:54 2019 +0100
@@ -44,6 +44,7 @@
     rx_nonprintable = QRegExp(r"""(\\x\d\d)+""")
     
     noOfItemsStr = QCoreApplication.translate("VariablesViewer", "{0} items")
+    unsized = QCoreApplication.translate("VariablesViewer", "unsized")
     
     arrayTypes = {
         'list', 'tuple', 'dict', 'set', 'frozenset', 'numpy.ndarray',
@@ -178,8 +179,11 @@
             self.indicator = VariableItem.Type2Indicators.get(dtype, '')
         
         if dtype == 'numpy.ndarray':
-            self.childCount = int(dvalue.split('x')[0])
-            dvalue = VariableItem.noOfItemsStr.format(dvalue)
+            if dvalue:
+                self.childCount = int(dvalue.split('x')[0])
+                dvalue = VariableItem.noOfItemsStr.format(dvalue)
+            else:
+                dvalue = VariableItem.unsized
             self.hasChildren = True
         elif dtype in VariableItem.arrayTypes:
             self.childCount = int(dvalue)

eric ide

mercurial