-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Series.sum has inconsistent return type #9733
Comments
We don't support numeric methods on strings, but otherwise this seasons reasonable to me. Want to give putting together a patch a try? |
@remiremi yeah I don't think we coerce scalars to anything. This could be made more consistent. We should in general NOT be returning python scalars. |
…ar for empty series
… scalar for empty series
…ar for empty series
This now returns correctly a numpy type:
So repurpose this issue to add a test to confirm this. |
Closing this as we have an issue to convert the Series dtype to object for empty creation, and #19813 is there for the strange return value. |
Series.sum returns a numpy type, except when it's empty, in which case it returns a python int of value "0":
This poses a problem when I do
1 / myserie.sum()
because I expect to obtainnp.inf
rather than a divison by 0 exception.I think the return type of
Series.sum()
for empty series should be inferred from the Series's dtype This way,Series([], dtype='str').sum()
would return an empty string, andSeries([]).sum()
would returnnp.float64(0)
since an empty series' default type seems to be float64.Tested with Pandas 0.16.0
The text was updated successfully, but these errors were encountered: