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

Behavior of sum and infinity #968

Closed
craustin opened this issue Mar 26, 2012 · 2 comments
Closed

Behavior of sum and infinity #968

craustin opened this issue Mar 26, 2012 · 2 comments

Comments

@craustin
Copy link

import numpy as np
from pandas import Series
a = [np.nan, 1]
b = [np.inf, 1]
print Series(a).sum() #1
print Series(b).sum() #2
print np.sum(a) #3
print np.sum(b) #4

I understand that pandas has made the design decision that sums with nans will drop nans (#1), but why is infinity dropped in the same way? I don't see why np.inf + 5 could reasonably be 5. numpy returns np.inf in this case.

@wesm
Copy link
Member

wesm commented Mar 26, 2012

This arose entirely out of practicality--the unfortunate alternative is that you need to add a LOT of infinity checks in your code (and replace infinity with NA in many cases). I agree it's probably a good idea to replace all usages of np.isfinite(x) with -np.isnan(x) .

@wesm
Copy link
Member

wesm commented Mar 28, 2012

Initially it seemed like treating infs as NAs as the way to go but now
not so sure

On Mon, Mar 26, 2012 at 1:36 PM, Chang She
reply@reply.github.com
wrote:

The logic is the same in both cases that Series.sum should only sum over
valid numerical values. Series([inf, 3, 4]).sum() is not inf + 3 +4, but
instead it is 3 + 4.

On Mon, Mar 26, 2012 at 10:48 AM, Craig Austin <
reply@reply.github.com

wrote:

import numpy as np
from pandas import Series
a = [np.nan, 1]
b = [np.inf, 1]
print Series(a).sum() #1
print Series(b).sum() #2
print np.sum(a) #3
print np.sum(b) #4

I understand that pandas has made the design decision that sums with nans
will drop nans (#1), but why is infinity dropped in the same way?  I don't
see why np.inf + 5 could reasonably be 5.  numpy returns np.inf in this
case.


Reply to this email directly or view it on GitHub:
#968


Reply to this email directly or view it on GitHub:
#968 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants