-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Preserve EA dtype in DataFrame.stack #23285
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
381b073
Preserve EA dtype in DataFrame.stack
TomAugspurger 428f230
sparse
TomAugspurger 0d39be0
multi test
TomAugspurger fc37932
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger 7bb5a5e
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger 7e9224a
multiple columns
TomAugspurger d6661cb
remove pdb
TomAugspurger 3d41f5b
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger 9f91df0
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger 144d117
really object
TomAugspurger 98f75c9
remove loc
TomAugspurger 88f7f3e
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger 2b858b8
Fixed merge conflict
TomAugspurger 88f08c7
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger d305c86
Merge remote-tracking branch 'upstream/master' into ea-stack
TomAugspurger f6aeafa
lint
TomAugspurger 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
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 |
---|---|---|
|
@@ -173,6 +173,28 @@ def test_merge(self, data, na_value): | |
dtype=data.dtype)}) | ||
self.assert_frame_equal(res, exp[['ext', 'int1', 'key', 'int2']]) | ||
|
||
@pytest.mark.parametrize("columns", [ | ||
["A", "B"], | ||
pd.MultiIndex.from_tuples([('A', 'a'), ('A', 'b')], | ||
names=['outer', 'inner']), | ||
]) | ||
def test_stack(self, data, columns): | ||
df = pd.DataFrame({"A": data[:5], "B": data[:5]}) | ||
df.columns = columns | ||
result = df.stack() | ||
expected = df.astype(object).stack() | ||
# we need a second astype(object), in case the constructor inferred | ||
# object -> specialized, as is done for period. | ||
expected = expected.astype(object) | ||
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. This is kinda strange. For In [1]: import pandas as pd
In [2]: a = pd.core.arrays.period_array(['2000', '2001'], freq='D')
In [3]: pd.DataFrame({"A": a, "B": a}).astype(object).dtypes
Out[3]:
A object
B object
dtype: object
In [4]: pd.DataFrame({"A": a, "B": a}).astype(object).stack().dtype
Out[4]: period[D] (that's on master) |
||
|
||
if isinstance(expected, pd.Series): | ||
assert result.dtype == df.iloc[:, 0].dtype | ||
else: | ||
assert all(result.dtypes == df.iloc[:, 0].dtype) | ||
|
||
result = result.astype(object) | ||
self.assert_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("index", [ | ||
# Two levels, uniform. | ||
pd.MultiIndex.from_product(([['A', 'B'], ['a', 'b']]), | ||
|
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
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.