# Merge lp:~cody-stevens/graphite/graphite into lp:graphite

Proposed by Cody Stevens on 2012-10-31
Status: Needs review lp:~cody-stevens/graphite/graphite lp:graphite 18 lines (+2/-2)1 file modifiedwebapp/graphite/render/functions.py (+2/-2) bzr merge lp:~cody-stevens/graphite/graphite
Reviewer Review Type Date Requested Status
graphite-dev 2012-10-31 Pending

### Description of the change

Graphite usually treats 'None' values as missing data which results in breaks in the lines of the graph. However, the sum and diff functions will basically treat them as a 0 value which can make the graph inaccurate when adding or diffing 2 series. This update checks to make sure that there are at least 2 values to be summed or diffed and if not will not do the diff/sum. This falls more in line with the way that graphite handles 'None' values IMHO.

 Sidnei da Silva (sidnei) wrote on 2012-10-31: #

Hi Cody,

## Unmerged revisions

865. By Cody Stevens on 2012-10-31

Updated safeDiff and safeSum to require 2 values to be summed/diffed.

## Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
 1 === modified file 'webapp/graphite/render/functions.py' 2 --- webapp/graphite/render/functions.py 2012-10-16 01:41:01 +0000 3 +++ webapp/graphite/render/functions.py 2012-10-31 17:01:24 +0000 4 @@ -46,12 +46,12 @@ 5 #Utility functions 6 def safeSum(values): 7 safeValues = [v for v in values if v is not None] 8 - if safeValues: 9 + if safeValues and len(safeValues) > 1: 10 return sum(safeValues) 11 12 def safeDiff(values): 13 safeValues = [v for v in values if v is not None] 14 - if safeValues: 15 + if safeValues and len(safeValues) > 1: 16 values = map(lambda x: x*-1, safeValues[1:]) 17 values.insert(0, safeValues[0]) 18 return sum(values)

## Subscribers

People subscribed via source and target branches

to all changes: