Skip to content

to_sparse and assign is giving the wrong results. #19163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wellimbharath opened this issue Jan 10, 2018 · 2 comments · Fixed by #19178
Closed

to_sparse and assign is giving the wrong results. #19163

wellimbharath opened this issue Jan 10, 2018 · 2 comments · Fixed by #19178
Labels
Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type
Milestone

Comments

@wellimbharath
Copy link

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?

@jreback
Copy link
Contributor

jreback commented Jan 10, 2018

xref to #18924

This is quite tricky actually; you are starting with a SparseDataFrame which has some special properties; .assign() should convert this to a DataFrame.

So this is currently not supported.

cc @hexgnu

@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Dtype Conversions Unexpected or buggy dtype conversions Sparse Sparse Data Type Difficulty Advanced labels Jan 10, 2018
@jreback jreback added this to the Next Major Release milestone Jan 10, 2018
@hexgnu
Copy link
Contributor

hexgnu commented Jan 11, 2018

Just put together a quick bug fix for this.

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants