BUG: Fix nanvar for large float16 arrays #40738
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Summary of bug:
Above a certain length, calling
.std()and.var()on a Series or DataFrame fails for float types. The is easily shown with float16 in the following example:What is happening here is that both
countanddoverflow toinfas 65519 is the largest integer float16 can represent. Example:This makes the variance go to 0.0. Since the
avgcalculation on line 927 of this file casts to float64 anyway, it seems like there is no downside to not castingcountandd. It will also improve accuracy in cases where the overflow does not happen.INSTALLED VERSIONS
commit : f2c8480
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 20.3.0
Version : Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.2.3
numpy : 1.20.1