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

to_sparse and assign is giving the wrong results. #19163

Closed
Bharathsh36 opened this Issue Jan 10, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@Bharathsh36

Bharathsh36 commented Jan 10, 2018

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

This comment has been minimized.

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 this to the Next Major Release milestone Jan 10, 2018

@hexgnu

This comment has been minimized.

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