Skip to content

BUG: When upsampling an empty dataframe, the index type changes from DatetimeIndex to MultiIndex #55572

@creid-hartree

Description

@creid-hartree

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame([], index=pd.DatetimeIndex([]))

# this returns a MultiIndex rather than a DatetimeIndex
df.resample("D").ffill().index

Issue Description

When upsampling an empty dataframe, the index type changes from DatetimeIndex to MultiIndex.

This applies to all the upsampling methods, i.e. resample followed by fillna, ffill, bfill, nearest, asfreq, or interpolate.

This only happens on empty dataframes or series, and only when upsampling (for example resample("D").mean() works as expected).

This regression was introduced in pandas 2.0.0

Expected Behavior

The resampled dataframe should have a DatetimeIndex rather than a MultiIndex.

Installed Versions

pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3
tzdata : 2023.3

all others None

Metadata

Metadata

Assignees

Labels

BugRegressionFunctionality that used to work in a prior pandas versionResampleresample method

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions