Fix vline and vrect datetime object annotation mean calculation by mosh3eb · Pull Request #5519 · plotly/plotly.py

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.