Skip to content

API: Sparse Return Types #12855

Closed
Closed
@gfyoung

Description

@gfyoung

The documentation of SparseArray.cumsum says it returns a Series, but that is not the case:

>>> from pandas import SparseArray, np
>>> data = np.arange(10)
>>> s = SparseArray(data, fill_value=np.nan)
>>> type(s.cumsum())
<class 'pandas.sparse.array.SparseArray'>
>>>
>>> s = SparseArray(data, fill_value=2)
>>> type(s.cumsum())
<class 'numpy.ndarray'>

Given that to_dense now returns self.values and ignores fill_value, this current behaviour in cumsum seems illogical and should probably just return SparseArray regardless. At the very least though, I think a documentation fix is in order.

EDIT: there is a similar issue with SparseSeries that should also be addressed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions