BUG: DataFrame.mode index dtype is not type stable · Issue #33321 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of pandas.
- (optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
The .index.dtype
is not stable for DataFrame.mode. It depends on whether the DataFrame is empty and possible the dtypes
In [60]: pd.DataFrame([], columns=['a', 'b']).mode().index.dtype Out[60]: dtype('O')
Problem description
The index dtype should always be Int64, to match the non-empty case
Expected Output
In [61]: pd.DataFrame({"A": ['a']}).mode().index.dtype Out[61]: dtype('int64')