Skip to content

Fix timeline bar lengths across daylight saving changes - #5796

Open
mottopanikeiku wants to merge 2 commits into
plotly:mainfrom
mottopanikeiku:fix-timeline-daylight-saving
Open

mottopanikeiku wants to merge 2 commits into
plotly:mainfrom
mottopanikeiku:fix-timeline-daylight-saving

Conversation

@mottopanikeiku

Copy link
Copy Markdown

Link to issue

Closes #4611

Description of change

px.timeline now calculates bar lengths in the same local wall-clock coordinates that date axes display, so bars with timezone-aware dates no longer end an hour early or late across daylight saving transitions. The original start column and its timezone metadata are unchanged.

Demo

For the issue's US/Pacific midnight-to-midnight examples:

Interval Before: displayed endpoint After: displayed endpoint
March 10–11, 2024 March 10, 23:00 March 11, 00:00
November 5–6, 2023 November 6, 01:00 November 6, 00:00
import pandas as pd
import plotly.express as px

for day in ("2024-03-10", "2023-11-05"):
    start = pd.Timestamp(day, tz="US/Pacific")
    df = pd.DataFrame({
        "Start": [start],
        "Finish": [start + pd.DateOffset(days=1)],
        "Task": ["Job A"],
    })
    fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
    print(fig.data[0].x)  # [86400000] for both local-calendar days

Testing strategy

The regression checks bar lengths, start coordinates, and reconstructed endpoints around both transitions, with UTC and timezone-naive controls, across the Polars, PyArrow, and pandas constructors. Before the fix, pytest tests/test_optional/test_px/test_px_functions.py -k timeline_daylight_saving gave 5 failures (every US/Pacific case off by an hour); after it, the whole file passes (88 passed, 7 skipped, the skips being existing pandas 3/PyArrow hierarchy-chart cases). ruff check and ruff format --check pass on the changed files.

Additional information (optional)

I used AI assistance (OpenAI Codex and Claude) to investigate, implement, and test this change. No new dependencies or public API.

Guidelines

I calculate timeline bar lengths in the same local wall-clock coordinates used by date axes, so timezone-aware endpoints remain aligned across daylight saving changes. I leave the original start column unchanged and cover spring, autumn, UTC, and naive timestamps across dataframe backends.

Fixes plotly#4611

Signed-off-by: mottopanikeiku <176798723+mottopanikeiku@users.noreply.github.com>
@camdecoster

Copy link
Copy Markdown
Contributor

@mottopanikeiku have you reviewed the code and tests yourself?

@mottopanikeiku

Copy link
Copy Markdown
Author

@camdecoster i have! its a very small diff hahah like 13 lines

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

px.timeline with a Daylight Savings Time scenario - missing/extra hour

2 participants