Skip to content

Series.sum has inconsistent return type #9733

@remiremi

Description

@remiremi

Series.sum returns a numpy type, except when it's empty, in which case it returns a python int of value "0":

In [2]: type(pd.Series([0]).sum())
Out[2]: numpy.int64

In [3]: type(pd.Series().sum())
Out[3]: int

This poses a problem when I do 1 / myserie.sum() because I expect to obtain np.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, and Series([]).sum() would return np.float64(0) since an empty series' default type seems to be float64.

Tested with Pandas 0.16.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions