-
-
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
Changes from 9 commits
165fd72
e0c1a8d
f765acf
109d312
519a140
9d20ff5
d460db6
bae2bd8
047ae40
c0fffe8
6b2b9bd
efc0603
dac5f32
6524a6c
6c71101
e57aa51
f2f29bc
07d9ad5
148b77d
99f8280
c4e244a
668189f
20858db
4f95523
7ab1155
475f158
bdf49d3
f96453e
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 |
---|---|---|
|
@@ -517,7 +517,7 @@ def factorize(index): | |
# For homogeneous EAs, frame._values will coerce to object. So | ||
# we concatenate instead. | ||
dtypes = list(frame.dtypes._values) | ||
dtype = dtypes[0] | ||
dtype = dtypes[0] if len(dtypes) > 0 else 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. What if you return the Series right away if the dataframe is empty?
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. But you would still need to solve unstacking from an empty 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. likely you can just add a |
||
|
||
if is_extension_array_dtype(dtype): | ||
arr = dtype.construct_array_type() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1273,6 +1273,18 @@ def test_stack_timezone_aware_values(): | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_stack_empty_frame(): | ||
tm.assert_series_equal( | ||
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 result= pls parameterize these cases add a comment with the issue number |
||
DataFrame().stack(), | ||
Series(index=MultiIndex([[], []], [[], []]), dtype=np.float64), | ||
) | ||
tm.assert_series_equal( | ||
DataFrame().stack(dropna=True), | ||
Series(index=MultiIndex([[], []], [[], []]), dtype=np.float64), | ||
) | ||
tm.assert_frame_equal(DataFrame().stack().unstack(), DataFrame()) | ||
|
||
|
||
def test_unstacking_multi_index_df(): | ||
# see gh-30740 | ||
df = DataFrame( | ||
|
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 you elaborate a bit on what is changing.
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.
I have elaborate this a bit in the latest commit