plotly / plotly/plotly.py

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

Open
#4,611 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Problem:
When using px.timeline on a range where a Daylight Savings Time switch occurs & time zones are in the timestamps, I observe an unexpectedly shorter/longer duration of the bar.

Example A - March - missing an hour

import pandas as pd
import plotly.express as px

df = pd.DataFrame(dict(
    x_start=[
        pd.Timestamp("2024-03-09", tz="US/Pacific"),
        pd.Timestamp("2024-03-10", tz="US/Pacific"),
        pd.Timestamp("2024-03-11", tz="US/Pacific"),
    ],
    x_end=[
        pd.Timestamp("2024-03-10", tz="US/Pacific"),
        pd.Timestamp("2024-03-11", tz="US/Pacific"),
        pd.Timestamp("2024-03-12", tz="US/Pacific"),
    ],
    y=[1, 1, 1],
))

px.timeline(df, x_start="x_start", x_end="x_end", y="y")

image

As you can see, for the DST day (March 10, 2024), the end date is unexpectedly 1 hour early, unlike the other days.

Example B - November - extra hour

import pandas as pd
import plotly.express as px

df = pd.DataFrame(dict(
    x_start=[
        pd.Timestamp("2023-11-05", tz="US/Pacific"),
    ],
    x_end=[
        pd.Timestamp("2023-11-06", tz="US/Pacific"),
    ],
    y=[1],
))

px.timeline(df, x_start="x_start", x_end="x_end", y="y")

image

In this example, 1 hour is unexpectedly added to the end.

Testing environment:

  • Google Colab (also experienced on VS Code & html)
  • Latest version of plotly (5.22.0).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing both pandas and px.timeline examples from the issue, covering the March and November DST transitions. Trace the px.timeline entry point through its handling of timezone-aware timestamps and add regression coverage for both cases. Done means each bar spans the intended local calendar interval without a missing or extra hour.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.