-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix GH-29442 DataFrame.groupby doesn't preserve _metadata #35688
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
jreback
merged 26 commits into
pandas-dev:master
from
Japanuspus:BUG_GH29442_frame_groupby_metadata
Oct 14, 2020
Merged
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7cc4d53
Fix GH-29442 DataFrame.groupby doesn't preserve _metadata
Japanuspus 0ab766d
Fix most PEP8 issues
Japanuspus d7b42e3
Fix remaining PEP8 issues
Japanuspus fbc602c
Apply "black" styling and fix typo
Japanuspus e9c64ac
Fix import sorting issues reported by `isort`
Japanuspus ec7fd00
Make testcase more concise
Japanuspus 1405667
Include test from original issue
Japanuspus 8d3d896
Fix metadata handling for `.groupby(...).sum()`
Japanuspus 39e9f33
Apply black format
Japanuspus 7075ef2
Remove xfail decorator for `sum` aggregation test
Japanuspus 05a3365
Merge branch 'master' into BUG_GH29442_frame_groupby_metadata
Japanuspus 4720c97
Move `__finalize__` outsize context handler
Japanuspus 6b290e8
Revert __finalize__ call in DataSplitter
Japanuspus a2bdc3d
Add performance test counting __finalize__ calls
Japanuspus 2af8447
Add whatsnew entry
Japanuspus ec3eeb1
Move __finalize__ inside context manager
Japanuspus 5487563
Fix typo in whatsnew entry
Japanuspus 8bfd08d
Revert 1.1.3 whatsnew entry
Japanuspus 7d9320a
Merge branch 'master' into BUG_GH29442_frame_groupby_metadata
Japanuspus 7878041
Add 1.1.4 whatsnew entry
Japanuspus 5548699
Revert all changes not strictly related to issue
Japanuspus 18e8ff5
Use descriptive names for unit tests
Japanuspus 57694ae
Remove extraneous imports
Japanuspus d3088a3
Merge master into BUG_GH29442_frame_groupby_metadata
Japanuspus d86ae78
Delete tests for custom metadata
Japanuspus 6227894
Remove reference to internal class from whatsnew
Japanuspus 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pandas import DataFrame | ||
|
||
|
||
class CustomDataFrame(DataFrame): | ||
""" | ||
Extension of DataFrame as described in [guidelines] | ||
|
||
[guidelines]: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#override-constructor-properties # noqa | ||
""" | ||
|
||
_metadata = ["_custom_metadata"] | ||
|
||
@property | ||
def _constructor(self): | ||
return CustomDataFrame | ||
|
||
|
||
def test_groupby_with_custom_metadata(): | ||
custom_df = CustomDataFrame( | ||
[[11, 12, 0], [21, 22, 0], [31, 32, 1]], columns=["a", "b", "g"] | ||
) | ||
custom_df._custom_metadata = "Custom metadata" | ||
|
||
for _, group_df in custom_df.groupby("g"): | ||
assert group_df._custom_metadata == "Custom metadata" |
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.