-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: allow attrs to be propagated via pd.concat #42252
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 16 commits
56e1d4f
93da2b2
2043634
23541a8
b349e96
d2ba70f
60cce3b
757726b
28614cb
bb59b1b
298e572
e172863
e41822f
ab34f2f
49bd5b1
2c2e0d1
cfcc6d1
cadfb63
dd19672
93cc257
e679918
08e6fab
f49f027
0aee5e5
cefc444
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 |
---|---|---|
|
@@ -698,3 +698,36 @@ def test_concat_posargs_deprecation(): | |
result = concat([df, df2], 0) | ||
expected = DataFrame([[1, 2, 3], [4, 5, 6]], index=["a", "b"]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_concat_retain_attrs_df(): | ||
# GH#41828 | ||
d = {"col1": [1, 2], "col2": [3, 4]} | ||
df1 = DataFrame(data=d) | ||
df1.attrs = {1: 1} | ||
df2 = DataFrame(data=d) | ||
df2.attrs = {1: 1} | ||
df = concat([df1, df2]) | ||
assert df.attrs[1] == 1 | ||
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. use assert_equal (u can also compare attrs if u want) though should prob add a flag to do this in the asset_ routines (i don't think we have this) 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. @jreback Thank you for the review. I wonder if do you mean pandas._testing.assert_equal? It seems that pandas._testing.assert_equal cannot handle comparison between integers. |
||
|
||
|
||
def test_concat_retain_attrs_series(): | ||
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. paramterize over series and frame and use assert_equal |
||
# GH#41828 | ||
d = [1, 2] | ||
df1 = Series(data=d) | ||
df1.attrs = {1: 1} | ||
df2 = Series(data=d) | ||
df2.attrs = {1: 1} | ||
df = concat([df1, df2]) | ||
assert df.attrs[1] == 1 | ||
|
||
|
||
def test_concat_drop_attrs(): | ||
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. same |
||
# GH#41828 | ||
d = {"col1": [1, 2], "col2": [3, 4]} | ||
df1 = DataFrame(data=d) | ||
df1.attrs = {1: 1} | ||
df2 = DataFrame(data=d) | ||
df2.attrs = {1: 2} | ||
df = concat([df1, df2]) | ||
assert len(df.attrs) == 0 |
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.
this is already handled above no? L5448
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.
@jreback Thanks for the review. No.
So during concatenation, the
other
is aconcatenator
, which is not anNDFrame
.So it will not pass the if statement in L5447.
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.
can remove the comment