-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Ensure series/frame mode() keeps int index #38732
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 1 commit
98f20e2
21210fc
751a497
ba3cb9a
0e598d1
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 |
---|---|---|
|
@@ -9241,7 +9241,12 @@ def mode( | |
def f(s): | ||
return s.mode(dropna=dropna) | ||
|
||
return data.apply(f, axis=axis) | ||
data = data.apply(f, axis=axis) | ||
# Ensure index is type stable (should always use int index) | ||
if data.empty: | ||
data.index = Index([], dtype="int64") | ||
|
||
return data | ||
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. Empty result case doesn't hit |
||
|
||
def quantile( | ||
self, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pandas import DataFrame, Index | ||
import pandas._testing as tm | ||
|
||
|
||
def test_empty_df_mode(): | ||
df = DataFrame([], columns=["a", "b"]) | ||
result = df.mode() | ||
expected = DataFrame([], columns=["a", "b"], index=Index([], dtype="int64")) | ||
tm.assert_frame_equal(result, expected) | ||
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. Couldn't find any 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. We keep them in 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. Ah thanks! Sorry for missing that |
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.
is this right for 32-bit machines?
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.
Changed to
int
, thanks for catching that