Sections
Timeline
Browse Source
New Ticket
Sub-Sections
Download
Comma-delimited Text
Tab-delimited Text
RSS Feed
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Ticket #5 (closed defect: fixed)

Opened 6 months ago

Last modified 3 months ago

Regression: "missing" values not supported by scaling

Reported by: athomas Owned by:
Priority: major Version: 0.2.0
Keywords: Cc:

Description

The following code triggers a traceback due to the None being passed to the scaling functions. Attached patch is a possible solution.

>>> from pygooglechart import *
>>> c = SimpleLineChart(200, 100)
>>> c.add_data([1, 2, 3, 4, 5, None, 7, 8, 9])
0
>>> c.download('foo.png')

Attachments

Change History

Changed 6 months ago by anonymous

Tried to attach patch, failed :(

OSError: [Errno 13] Permission denied: '/home/trac/pygooglechart/attachments/ticket'

Anyhoo, here it is inline:

Index: pygooglechart.py
===================================================================
--- pygooglechart.py	(revision 42)
+++ pygooglechart.py	(working copy)
@@ -472,14 +472,19 @@
         else:
             return ExtendedData
 
+    def _filter_none(self, data):
+        return [r for r in data if r is not None]
+
     def data_x_range(self):
         """Return a 2-tuple giving the minimum and maximum x-axis
         data range.
         """
         try:
-            lower = min([min(s) for type, s in self.annotated_data()
+            lower = min([min(self._filter_none(s))
+                         for type, s in self.annotated_data()
                          if type == 'x'])
-            upper = max([max(s) for type, s in self.annotated_data()
+            upper = max([max(self._filter_none(s))
+                         for type, s in self.annotated_data()
                          if type == 'x'])
             return (lower, upper)
         except ValueError:
@@ -490,9 +495,11 @@
         data range.
         """
         try:
-            lower = min([min(s) for type, s in self.annotated_data()
+            lower = min([min(self._filter_none(s))
+                         for type, s in self.annotated_data()
                          if type == 'y'])
-            upper = max([max(s) + 1 for type, s in self.annotated_data()
+            upper = max([max(self._filter_none(s)) + 1
+                         for type, s in self.annotated_data()
                          if type == 'y'])
             return (lower, upper)
         except ValueError:
@@ -536,8 +543,14 @@
                 scale_range = y_range
             elif type == 'marker-size':
                 scale_range = (0, max(dataset))
-            scaled_data.append([data_class.scale_value(v, scale_range)
-                                for v in dataset])
+            scaled_dataset = []
+            for v in dataset:
+                if v is None:
+                    scaled_dataset.append(None)
+                else:
+                    scaled_dataset.append(
+                        data_class.scale_value(v, scale_range))
+            scaled_data.append(scaled_dataset)
         return scaled_data
 
     def add_data(self, data):

Changed 3 months ago by gak

  • status changed from new to closed
  • resolution set to fixed

Add/Change #5 (Regression: "missing" values not supported by scaling)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.