Skip to content
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

BUG: DataFrame.resample is changing the index type to MultiIndex when the dataframe is empty #61174

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

morotti
Copy link
Contributor

@morotti morotti commented Mar 24, 2025

BUG: DataFrame.resample is changing the index type to MultiIndex when the dataframe is empty

very easy bug to reproduce. the bug has been opened for 1 year.

# repro
import pandas as pd

df = pd.DataFrame(columns = ["a", "b"], index = pd.DatetimeIndex([]))
sampled = df.resample("8h").apply(pd.Series.mean)

print(df.index)
print(sampled.index)

output on pandas 1

DatetimeIndex([], dtype='datetime64[ns]', freq=None)
DatetimeIndex([], dtype='datetime64[ns]', freq='8H')

output on pandas 2 and main branch

DatetimeIndex([], dtype='datetime64[ns]', freq=None)
MultiIndex([], )

@mroeschke mroeschke added MultiIndex Resample resample method labels Mar 24, 2025
@mroeschke mroeschke added this to the 3.0 milestone Mar 24, 2025
@mroeschke mroeschke merged commit 78acf94 into pandas-dev:main Mar 24, 2025
46 of 47 checks passed
@mroeschke
Copy link
Member

Thanks @morotti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiIndex Resample resample method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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