Bug fix: Zero-length partitions result in NaN for overall mean & variance

In the current code, when two merging partitions happen to have zero-length, the return mean will be NaN. Consequently, the result of mean or variance after reducing over all partitions will also be NaN, which is not correct if there are other partitions with non-zero length. This patch fixes this issue.