-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Attributes are lost when subsetting columns in groupby #35444
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
493b0d2
BUG: Attributes are lost when subsetting columns
rhshadrach b4e0139
Whatsnew
rhshadrach 3444eb2
Merge branch 'master' into group_keys
rhshadrach e6099b7
Fixed whatsnew
rhshadrach d048a40
Merge branch 'group_keys' of https://github.com/rhshadrach/pandas int…
rhshadrach 5f223af
Merge remote-tracking branch 'upstream/master' into group_keys
rhshadrach 4b16e07
Merge branch 'master' into group_keys
rhshadrach 0d05b4b
Removed trailing whitespace
rhshadrach 35f03b5
Added tests back
rhshadrach 161bbf0
Added propagating attributes in the ndim=1 case
rhshadrach ee46137
Merge branch 'master' of https://github.com/pandas-dev/pandas into gr…
rhshadrach fdbd5c2
Changed some tests from skip to xfail
rhshadrach 216e11b
Reparametrized tests
rhshadrach e51e730
black
rhshadrach 2d42774
Merge branch 'master' of https://github.com/pandas-dev/pandas into gr…
rhshadrach 28db1ff
Merge branch 'master' of https://github.com/pandas-dev/pandas into gr…
rhshadrach c4515b3
Removed xfail for as_index case
rhshadrach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2069,3 +2069,36 @@ def test_group_on_two_row_multiindex_returns_one_tuple_key(): | |
assert len(result) == 1 | ||
key = (1, 2) | ||
assert (result[key] == expected[key]).all() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"attr, value", | ||
[ | ||
("axis", 1), | ||
("level", "a"), | ||
("as_index", False), | ||
("sort", False), | ||
("group_keys", False), | ||
("squeeze", True), | ||
("observed", True), | ||
("dropna", False), | ||
], | ||
) | ||
@pytest.mark.filterwarnings( | ||
"ignore:The `squeeze` parameter is deprecated:FutureWarning" | ||
) | ||
def test_subsetting_columns_keeps_attrs(attr, value): | ||
# GH 9959 - When subsetting columns, don't drop attributes | ||
df = pd.DataFrame({"a": [1], "b": [2], "c": [3]}) | ||
if attr != "axis": | ||
df = df.set_index("a") | ||
|
||
expected = df.groupby("a", **{attr: value}) | ||
|
||
result = expected[["b"]] | ||
rhshadrach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert getattr(result, attr) == getattr(expected, attr) | ||
|
||
if attr in ("axis", "as_index"): | ||
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. can you xfail these in the parameter list instead |
||
pytest.xfail("GH 35443: Attribute currently not passed on to series") | ||
result = expected["b"] | ||
assert getattr(result, attr) == getattr(expected, attr) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.