-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pandas.DataFrame().stack() raise an error, while expected is empty #36185
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 19 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
165fd72
BUG: GH36113
steveya e0c1a8d
modify tests to avoid deprrecated errors
steveya f765acf
PEP 8 compliant
steveya 109d312
remove trailing white space
steveya 519a140
black format checked
steveya 9d20ff5
DataFrame().stack should return an empty Series with dtype np.float64…
steveya d460db6
PEP8 again.
steveya bae2bd8
remove trailing space...\
steveya 047ae40
add a comma to pass black lint
steveya c0fffe8
simply fixes and parameterize tests
steveya 6b2b9bd
add error messages when unstack frame and series with single level index
steveya efc0603
apply ValueError location
steveya dac5f32
change the place where error is raised
steveya 6524a6c
add a test for unstack series with one level of index. elaborate chan…
steveya 6c71101
adding type information to exception message.
steveya e57aa51
Merge branch 'master' into GH36113
jreback f2f29bc
fix black format problem
steveya 07d9ad5
resolve doc/source/whatsnew/v1.2.0.rst conflicts
steveya 148b77d
fix unittest assert error message
steveya 99f8280
change dtype of empty series and dataframe in test
steveya c4e244a
formatting
steveya 668189f
change intp to int64 in testing of stack unstack empty frame
steveya 20858db
Merge remote-tracking branch 'upstream/master' into GH36113
steveya 4f95523
ensure indexer is of type int64
steveya 7ab1155
Merge remote-tracking branch 'upstream/master' into GH36113
steveya 475f158
remove xfail
steveya bdf49d3
remove unsed import
steveya f96453e
Merge remote-tracking branch 'upstream/master' into GH36113
steveya 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 |
---|---|---|
|
@@ -1175,6 +1175,30 @@ def test_stack_timezone_aware_values(): | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("dropna", [True, False]) | ||
def test_stack_empty_frame(dropna): | ||
# GH 36113 | ||
expected = Series(index=MultiIndex([[], []], [[], []]), dtype=np.float64) | ||
result = DataFrame().stack(dropna=dropna) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("dropna", [True, False]) | ||
@pytest.mark.parametrize("fill_value", [None, 0]) | ||
def test_stack_unstack_empty_frame(dropna, fill_value): | ||
# GH 36113 | ||
result = DataFrame().stack(dropna=dropna).unstack(fill_value=fill_value) | ||
expected = DataFrame() | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_unstack_single_index_series(): | ||
# GH 36113 | ||
msg = r"index must be a MultiIndex to unstack.*" | ||
with pytest.raises(ValueError, match=msg): | ||
Series().unstack() | ||
|
||
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. You may want to specify I just looked at the test failure and it seems that it is caused by the warning in repr.
|
||
|
||
def test_unstacking_multi_index_df(): | ||
# see gh-30740 | ||
df = DataFrame( | ||
|
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.
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 test fails in 32 bit.
Looks like also a problem with the dtype.
I am not sure if that is critical, but what if you specify here
dtype=np.intp
?