to_sparse and assign is giving the wrong results. · Issue #19163 · pandas-dev/pandas (original) (raw)
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?