diff --git a/cpp/src/groupby/sort/group_tdigest.cu b/cpp/src/groupby/sort/group_tdigest.cu index 115048aef5d..0738e4c5730 100644 --- a/cpp/src/groupby/sort/group_tdigest.cu +++ b/cpp/src/groupby/sort/group_tdigest.cu @@ -535,10 +535,12 @@ struct get_scalar_minmax { __device__ thrust::tuple operator()(size_type group_index) { - // note: .element() is taking care of fixed-point conversions for us. - return {static_cast(col.element(group_offsets[group_index])), - static_cast( - col.element(group_offsets[group_index] + (group_valid_counts[group_index] - 1)))}; + auto const valid_count = group_valid_counts[group_index]; + return valid_count > 0 + ? thrust::make_tuple( + static_cast(col.element(group_offsets[group_index])), + static_cast(col.element(group_offsets[group_index] + valid_count - 1))) + : thrust::make_tuple(0.0, 0.0); } };