Skip to content

Comments

Fix vline and vrect datetime object annotation mean calculation#5519

Open
mosh3eb wants to merge 1 commit intoplotly:mainfrom
mosh3eb:fix/annotation-performance
Open

Fix vline and vrect datetime object annotation mean calculation#5519
mosh3eb wants to merge 1 commit intoplotly:mainfrom
mosh3eb:fix/annotation-performance

Conversation

@mosh3eb
Copy link

@mosh3eb mosh3eb commented Feb 20, 2026

Description

Fix: Enhanced support for datetime objects in add_vline and add_vrect annotations.

This fix addresses an issue where add_vline and add_vrect failed to correctly calculate annotation positions when using datetime.datetime objects on temporal axes.

Technical Summary:

  • Resolution: Updated the internal _mean() utility in plotly/basedatatypes.py to support date-like types by performing aggregation in numeric timestamp space (epoch milliseconds) before converting results back to ISO-formatted strings.
  • Impact: Ensures accurate mid-point placement for vertical rectangle annotations (vrect) and resolves TypeError exceptions when attempting to compute positions for vertical lines (vline) on date-formatted axes.
  • Verification: Includes new unit tests in tests/test_optional/test_autoshapes/test_annotated_shapes.py covering datetime.datetime object inputs for both add_vline and add_vrect.

Code PR

  • I have read through the contributing notes and understand the structure of the package.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples.
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a change in behavior, I have updated the relevant docstrings in the code.

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.

1 participant