Skip to content

BUG: DataFrame.resample() fails across DST transitions with NonExistentTimeError in timezone-aware data #62601

@msobhyy10

Description

@msobhyy10

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

# Example 1

df_1 = pd.DataFrame({
    "timestamp": pd.to_datetime([
        "2024-04-26 01:00:00",  # DST jump in Africa/Cairo
        "2024-04-27 00:00:00",
    ]),
    "value": [1, 2],
})

df_1["timestamp"] = df_1["timestamp"].dt.tz_localize("Africa/Cairo")
df_1 = df_1.set_index("timestamp").resample("D").mean()

# Example 2

df_2 = pd.DataFrame(
    {
        "timestamp": pd.to_datetime([
            "2024-04-24 00:00:00",
            "2024-04-25 00:00:00",
        ]),
        "value": [76.0, 42.0],
    }
)

df_2["timestamp"] = df_2["timestamp"].dt.tz_localize("Africa/Cairo")
df_2 = df_2.set_index("timestamp").resample("D").mean().reset_index()

Issue Description

DataFrame.resample() fails when resampling timezone-aware data that crosses a daylight saving time (DST) boundary.
This happens even when the data itself does not contain the nonexistent local time, because pandas internally generates bin edges that fall into DST gaps.


Example 1 — direct DST boundary in data

import pandas as pd

df = pd.DataFrame({
    "timestamp": pd.to_datetime([
        "2024-04-26 01:00:00",  # DST jump in Africa/Cairo
        "2024-04-27 00:00:00",
    ]),
    "value": [1, 2],
})

df = df.tz_localize("Africa/Cairo")
df = df.set_index("timestamp").resample("D").mean()

Error:

NonExistentTimeError: 2024-04-26 00:00:00

Example 2 — data before the boundary

df = pd.DataFrame(
    {
        "timestamp": pd.to_datetime([
            "2024-04-24 00:00:00",
            "2024-04-25 00:00:00",
        ]),
        "value": [1, 2],
    }
)

df["timestamp"] = df["timestamp"].dt.tz_localize("Africa/Cairo")
df = df.set_index("timestamp").resample("D").mean().reset_index()

Fails because resample generates a nonexistent edge (2024-04-26 00:00:00).

Expected Behavior

Resampling should produce valid daily bins without raising an error.

Example 1 — direct DST boundary in data

timestamp value
0 2024-04-26 01:00:00+03:00 1
1 2024-04-27 00:00:00+03:00 2

Example 2 — data before the boundary

timestamp value
0 2024-04-24 00:00:00+02:00 1
1 2024-04-25 00:00:00+02:00 2

Installed Versions

INSTALLED VERSIONS

commit : 9c8bc3e
python : 3.11.13
python-bits : 64
OS : Linux
OS-release : 5.15.167.4-microsoft-standard-WSL2
Version : #1 SMP Tue Nov 5 00:21:55 UTC 2024
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.3
numpy : 2.3.3
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.0
Cython : None
sphinx : None
IPython : 9.6.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions