diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso index 9e9faa8a19b9..fa06bb821a6c 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso @@ -80,7 +80,9 @@ compute_bulk data statistics=[Count, Sum] = Error.throw (Illegal_Argument_Error ("Can only compute " + v.to_text + " on numerical data sets.")) handle_unsupported = Panic.catch Unsupported_Argument_Types handler=report_invalid - empty_map s = if (s == Count) || (s == Sum) then 0 else Error.throw Empty_Error + empty_map s = if (s == Count) || (s == Sum) then 0 else + if (s == Minimum) || (s == Maximum) then Error.throw Empty_Error else + Number.nan if data.length == 0 then statistics.map empty_map else count_min_max_values = if count_min_max then CountMinMax.new (CountMinMax.toObjectStream data.to_array) Comparator.new else Nothing diff --git a/test/Tests/src/Data/Statistics_Spec.enso b/test/Tests/src/Data/Statistics_Spec.enso index da2fcec05143..eac771cf9814 100644 --- a/test/Tests/src/Data/Statistics_Spec.enso +++ b/test/Tests/src/Data/Statistics_Spec.enso @@ -100,17 +100,19 @@ spec = values = number_set.compute_bulk stats values.map_with_index i->v->((expected.at i - v).abs < double_error) . any v->(v == True) . should_equal True - Test.specify "should be able to count valid values on empty Vector" <| + Test.specify "should be able to count and sum on empty Vector" <| [].compute . should_equal 0 + [].compute Sum . should_equal 0 - Test.specify "should fail with Empty_Error on other statistics for empty Vector" <| + Test.specify "should fail with Empty_Error for Minimuma and Maximum on empty Vector" <| [].compute Minimum . should_fail_with Vector.Empty_Error [].compute Maximum . should_fail_with Vector.Empty_Error - [].compute Sum . should_fail_with Vector.Empty_Error - [].compute Mean . should_fail_with Vector.Empty_Error - [].compute Variance . should_fail_with Vector.Empty_Error - [].compute Skew . should_fail_with Vector.Empty_Error - [].compute Kurtosis . should_fail_with Vector.Empty_Error + + Test.specify "should be NaN for other statistics sum on empty Vector" <| + [].compute Mean . is_nan . should_equal True + [].compute Variance . is_nan . should_equal True + [].compute Skew . is_nan . should_equal True + [].compute Kurtosis . is_nan . should_equal True Test.specify "should fail with Illegal_Argument_Error on number based statistics for text Vector" <| text_set.compute Sum . should_fail_with Illegal_Argument_Error