You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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) .
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.
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)
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.
The text was updated successfully, but these errors were encountered: