Skip to content

SparseDataFrame.to_coo does not convert the default fill value when is not 0 #24817

Closed
@gm-spacagna

Description

@gm-spacagna

DataFrame.sparse.to_coo() should raise when the fill_value is not zero, since scipy.sparse only supports filling with 0.

In [21]: df = pd.DataFrame({"A": pd.SparseArray([1, 1, 1, 2], fill_value=1)})

In [22]: df.sparse.to_coo().todense()
Out[22]:
matrix([[0],
        [0],
        [0],
        [2]])

That's incorrect. It should instead raise a ValueError with a nice message.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions