Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vpranckaitis committed Oct 23, 2020
1 parent 9815297 commit 6373c85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/query/functions/aggregation/quantile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ func makeQuantileFn(opType string, q float64) (aggregationFn, bool) {
}

func bucketedQuantileFn(q float64, values []float64, bucket []int) float64 {
if len(bucket) == 0 || len(values) == 0 {
return math.NaN()
}

if math.IsNaN(q) {
if math.IsNaN(q) || len(bucket) == 0 || len(values) == 0 {
return math.NaN()
}

Expand Down
18 changes: 10 additions & 8 deletions src/query/functions/aggregation/quantile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,16 @@ func TestQuantileFnSingleNonNan(t *testing.T) {
test.EqualsWithNansWithDelta(t, expected, actual, math.Pow10(-5))
}

func TestQuantileNanArgument(t *testing.T) {
values := []float64{0.0, 1.0}
buckets := []int{0, 1}

expected := math.NaN()
actual := bucketedQuantileFn(math.NaN(), values, buckets)

test.EqualsWithNans(t, expected, actual)
func TestQuantileNanAndEmptyArguments(t *testing.T) {
actual := []float64{
bucketedQuantileFn(0.8, []float64{}, []int{}),
bucketedQuantileFn(0.8, []float64{0.0, 1.0}, []int{}),
bucketedQuantileFn(0.8, []float64{}, []int{0, 1}),
bucketedQuantileFn(math.NaN(), []float64{0.0, 1.0}, []int{0, 1}),
}
for _, a := range actual {
require.True(t, math.IsNaN(a))
}
}

func TestQuantileCreationFn(t *testing.T) {
Expand Down

0 comments on commit 6373c85

Please sign in to comment.