Skip to content

Fix millisecond truncation in px.timeline bar lengths - #5898

Open
Enricoftw wants to merge 1 commit into
plotly:mainfrom
Enricoftw:timeline-fraction
Open

Enricoftw wants to merge 1 commit into
plotly:mainfrom
Enricoftw:timeline-fraction

Conversation

@Enricoftw

Copy link
Copy Markdown

Link to issue

Closes #5897

Description of change

Sub-millisecond events, such as a 500 µs event in a process log, disappear from px.timeline, and a 1.5 ms event is drawn as 1 ms. With pandas, a 1001 ms bar can also be drawn as 1000 ms.

process_dataframe_timeline calls dt.total_milliseconds(), which drops fractions and can round down with pandas. The fix converts integer duration ticks to milliseconds, preserving fractions and missing values.

Demo

import plotly.express as px

df = {
    "start": ["2026-01-01 00:00:00.000000"] * 2,
    "end": ["2026-01-01 00:00:00.000500", "2026-01-01 00:00:01.001000"],
    "event": ["pulse", "dwell"],
}
fig = px.timeline(df, x_start="start", x_end="end", y="event")
print(fig.data[0].x.tolist())  # before [0, 1000], after [0.5, 1001.0]

Testing strategy

test_timeline_fractional_milliseconds covers fractional, whole, negative and missing durations across DataFrame constructors. It fails on main and passes with the fix.

Additional information (optional)

Bar lengths for millisecond, microsecond and nanosecond data are floats again, as in 5.24.1. #5796 by @mottopanikeiku changes the same calculation for daylight saving time. If it lands first, I'll rebase.

AI disclosure: I used Codex (GPT-6.2 Sol) and Claude Code (Claude Opus 5.5) to find this, Claude Code (Claude Opus 5.5) to write the fix, the test and this description, and Codex (GPT-6.2 Sol), Antigravity CLI (Gemini 4 Neon) and a second Claude Code session to review them. I understand the change, and I ran the reproducer and the new test myself before and after the fix. I read and understood it before posting.

Guidelines

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>

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.

[BUG]: px.timeline draws sub-millisecond bars with zero width

1 participant