BUG: DataFrame.mode index dtype is not type stable · Issue #33321 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@TomAugspurger

Description

@TomAugspurger


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')