|
6 | 6 | from org.apache.commons.math3.stat.descriptive import DescriptiveStatistics |
7 | 7 | from org.apache.commons.math3.stat.descriptive import SummaryStatistics |
8 | 8 | import simplejson as json |
| 9 | +import math |
9 | 10 |
|
10 | 11 | @process( |
11 | 12 | title = 'Summarize Attribute Values', |
@@ -70,15 +71,16 @@ def run(features, attributeName): |
70 | 71 | stats['type'] = 'string' |
71 | 72 |
|
72 | 73 | if stats['type'] == 'number': |
73 | | - stats['min'] = ss.getMin() |
74 | | - stats['max'] = ss.getMax() |
75 | | - stats['range'] = stats['max'] - stats['min'] |
76 | | - stats['sum'] = ss.getSum() |
77 | | - stats['mean'] = ss.getMean() |
78 | | - stats['median'] = ds.getPercentile(50) |
79 | | - stats['stdDev'] = ds.getStandardDeviation() |
80 | | - stats['variance'] = ss.getPopulationVariance() |
| 74 | + if ss.getN(): |
| 75 | + stats['min'] = ss.getMin() |
| 76 | + stats['max'] = ss.getMax() |
| 77 | + stats['range'] = stats['max'] - stats['min'] |
| 78 | + stats['sum'] = ss.getSum() |
| 79 | + stats['mean'] = ss.getMean() |
| 80 | + stats['median'] = ds.getPercentile(50) |
| 81 | + stats['stdDev'] = ds.getStandardDeviation() |
| 82 | + stats['variance'] = ss.getPopulationVariance() |
81 | 83 |
|
82 | 84 | stats['uniqueValueCount'] = len(stats['uniqueValues']) |
83 | | - |
84 | | - return json.dumps(stats) |
| 85 | + |
| 86 | + return json.dumps(stats, allow_nan=False) |
0 commit comments