Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

negative variances #1090

Closed
turkeytest opened this issue Apr 20, 2012 · 1 comment
Closed

negative variances #1090

turkeytest opened this issue Apr 20, 2012 · 1 comment
Labels
Milestone

Comments

@turkeytest
Copy link

Hello,

It seems possible to have negative variances due to numerical inaccuracies. This is because nanops.py, line 120 does not take the absolute value of the result. Having negative values will cause std() to return NaN when it should be 0.

The code below should [probabilistically] recreate the problem. It could also be turned into a unit test.

Thanks!

from pandas import DataFrame
import numpy as np

random_repeated_rows = np.array( [np.random.random((10000,)),] * 10 )
my_var = DataFrame( random_repeated_rows ).var()

len( my_var[ my_var < 0 ] ) # returns a negative slightly less than half of the time
np.min( DataFrame( random_repeated_rows ).var() ) # returns a tiny negative -9.8686491077791697e-16
np.min( DataFrame( random_repeated_rows ).values.var(axis=0) ) # returns 0

@wesm
Copy link
Member

wesm commented Apr 22, 2012

Merged in master. Thanks @changhiskhan

@wesm wesm closed this as completed Apr 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants