Skip to content

Sum/product of empty object array is False/True #10639

Closed
@shoyer

Description

@shoyer

This strange behavior came up in pandas-dev/pandas#19813:

In [23]: np.array([], dtype=object).sum()
Out[23]: False

In [26]: np.array([], dtype=object).prod()
Out[26]: True

It's almost as if NumPy picks a dtype at random (e.g., bool in this case) to use for computing the result. A more obviously and likely more consistent choice would be to use the identities for the appropriate ufuncs (i.e., np.add.identity and np.mul.identity), which are the integers 0 and 1, respectively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions