polars icon indicating copy to clipboard operation
polars copied to clipboard

Optional ability for std() and var() to return NaN on size<=1 groups

Open JohnMount opened this issue 2 years ago • 0 comments

Problem description

I like that the Polars .std() and .var() are, in most cases, computing sample variance and sample standard deviation. I also understand the utility of returning zero for size 1 groups, as it doesn't start ugly NaN propagation. However, it would be really nice if .std() and .var() took an additional optional argument such as "return_nan: bool = False" that if set to True returned NaN on the size 1 groups instead of 0. This would allow Polars behavior be altered to match other systems. It is worth doing, as it saves having to repeat the same .over() condition in trying to apply such a correction at the user side.

JohnMount avatar Dec 30 '22 20:12 JohnMount