diff --git a/src/formpack/schema/fields.py b/src/formpack/schema/fields.py index cfa6881f..6a17dd35 100644 --- a/src/formpack/schema/fields.py +++ b/src/formpack/schema/fields.py @@ -507,8 +507,9 @@ def get_disaggregated_stats(self, metrics, top_splitters, for val, counter in metrics.items(): if val is None: continue - for splitter, count in counter.items(): - inversed_metrics[splitter].extend([val] * count) + for splitter, trans in top_splitters: + count = counter.pop(splitter, 0) + inversed_metrics[trans].extend([val] * count) for splitter, values in inversed_metrics.items(): diff --git a/tests/test_autoreport.py b/tests/test_autoreport.py index 9019a7cf..6aebf911 100644 --- a/tests/test_autoreport.py +++ b/tests/test_autoreport.py @@ -436,24 +436,24 @@ def test_disaggregate(self): 'stdev': 0.7071067811865476 } ), + ( + '2002-01-01', + { + 'mean': 2, + 'median': 2.0, + 'mode': 2, + 'stdev': 0.0 + } + ), ( '2003-01-01', { - 'mean': 1.0, + 'mean': 1, 'median': 1, 'mode': '*', 'stdev': '*' } ), - ( - '2002-01-01', - { - 'mean': 2.0, - 'median': 2.0, - 'mode': 2, - 'stdev': 0.0 - } - ) ) } )