Transformations: Calculate > Reduce should assume 0 for falsy values if field type is number (#110632)
* If number field, blank counts as 0 * Add test
This commit is contained in:
@@ -315,6 +315,12 @@ describe('fieldReducer.ts', () => {
|
||||
expect(preciseStats[`p${percentile}`]).toEqual(percentile);
|
||||
});
|
||||
});
|
||||
|
||||
// a number field can have empty strings as a result from previous transformations
|
||||
it('should count an empty string as 0 if the field type is number', () => {
|
||||
const numberField = createField('x', [1, '', 2], FieldType.number);
|
||||
expect(reduce(numberField, ReducerID.sum)).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFieldTypeForReducer', () => {
|
||||
|
||||
@@ -527,7 +527,7 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
||||
}
|
||||
|
||||
if (isNumberField) {
|
||||
calcs.sum += currentValue;
|
||||
calcs.sum += currentValue || 0;
|
||||
calcs.allIsNull = false;
|
||||
calcs.nonNullCount++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user