-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: assign doesnt cast SparseDataFrame to DataFrame #19178
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
Changes from 1 commit
6a10fa8
686ef8e
d874c7f
ac6213a
3042568
d900e11
a17a593
925186d
559434a
16a272d
e35bc17
2374bc6
a81796a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2713,7 +2713,9 @@ def assign(self, **kwargs): | |
8 9 0.549296 2.197225 | ||
9 10 -0.758542 2.302585 | ||
""" | ||
data = self.copy() | ||
|
||
# See GH19163 | ||
data = self.copy().to_dense() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you define assign on SparseDataFrame and only densify if nescessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and actually you don't want to densify, rather you want to do something like (in SparseDataFrame)
this actually ends up copying twice though. So the real solution is to move the guts of |
||
|
||
# do all calculations first... | ||
results = OrderedDict() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,13 @@ def test_assign(self): | |
result = df.assign(A=lambda x: x.A + x.B) | ||
assert_frame_equal(result, expected) | ||
|
||
# SparseDataFrame | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make a separate test |
||
# See GH 19163 | ||
result = df.to_sparse(fill_value=False).assign(newcol=False) | ||
expected = df.assign(newcol=False) | ||
assert type(result) is DataFrame | ||
assert_frame_equal(expected, result) | ||
|
||
def test_assign_multiple(self): | ||
df = DataFrame([[1, 4], [2, 5], [3, 6]], columns=['A', 'B']) | ||
result = df.assign(C=[7, 8, 9], D=df.A, E=lambda x: x.B) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
:class`DataFrame`
and so on here