Skip to content

sum() or prod() on an empty of all-NaN series  #20398

Closed
@karimpedia

Description

@karimpedia

In the documentation on Working with Missing Data in the latest release (0.22) it is mentioned that:

With sum or prod on an empty or all-NaN Series, or columns of a DataFrame, the result will be all-NaN.
Warning: These behaviors differ from the default in numpy where an empty sum returns zero.

while in fact, sum or prod on an empty or all-NaN Series behaves exactly similar to numpy, and this is also the case with the code sample given there:

In [1]: pd.Series([np.nan]).sum(), pd.Series([]).sum()
Out [1]: (0.0, 0.0)

In [2]: np.nansum([np.nan]), np.sum([])
Out [2]: (0.0, 0.0)

In [3]: pd.Series([np.nan]).prod(), pd.Series([]).prod()
Out [3]: (1.0, 1.0)

In [4]: np.nanprod([np.nan]), np.prod([])
Out [4]: (1.0, 1.0)

I wonder whether that's a typo in the docs or is it just not clear enough ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions