Skip to content

to_sparse and assign is giving the wrong results.  #19163

Closed
@wellimbharath

Description

@wellimbharath

Coming from SO, when a boolean scalar is assigned to a new column using assign, it is leading to wrong results. Why is that so?

df = pd.DataFrame({"a":[1,2,3]}).to_sparse(fill_value=False)
df.assign(newcol=False)

   a  newcol
0  1     0.0
1  2     0.0
2  3     0.0

This works as expected if the dataframe is dense i.e

df.to_dense().assign(newcol=False).to_sparse()

   a  newcol
0  1   False
1  2   False
2  3   False

Is this a bug or is this a genuine thing that's happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, ExplodeSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions