Title: Fix add_vline and add_hline with datetime axes by mosh3eb · Pull Request #5508 · plotly/plotly.py · GitHub
Open Graph Title: Fix add_vline and add_hline with datetime axes by mosh3eb · Pull Request #5508 · plotly/plotly.py
X Title: Fix add_vline and add_hline with datetime axes by mosh3eb · Pull Request #5508 · plotly/plotly.py
Description: Summary When using add_vline, add_hline, add_vrect, or add_hrect with annotation_text on datetime axes, plotly crashes with a TypeError because the _mean() helper function tries to call float(sum(x)) on datetime strings. Approach Instead of assuming input values are equal (which only works for vlines/hlines), _mean() now converts datetime-like values to milliseconds-since-epoch, computes the actual arithmetic mean, and converts back. This correctly handles annotation placement for ALL shapes with datetime axes, including rects where x0 != x1. The numeric fast path is unchanged -- datetime handling only activates when sum() raises TypeError Handles both date strings ("2018-09-24") and datetime.datetime objects Re-raises TypeError for truly unsupported types Changes plotly/shapeannotation.py: Added _is_date_string(), _datetime_str_to_ms(), _ms_to_datetime_str() helpers and updated _mean() with try/except fallback tests/test_optional/test_autoshapes/test_annotated_shapes.py: Added 5 tests covering datetime strings, datetime objects, vlines, hlines, and vrects Fixes #3065
Open Graph Description: Summary When using add_vline, add_hline, add_vrect, or add_hrect with annotation_text on datetime axes, plotly crashes with a TypeError because the _mean() helper function tries to call float(sum(x...
X Description: Summary When using add_vline, add_hline, add_vrect, or add_hrect with annotation_text on datetime axes, plotly crashes with a TypeError because the _mean() helper function tries to call float(sum(x...
Opengraph URL: https://github.com/plotly/plotly.py/pull/5508
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/commits/:range(.:format) |
| route-controller | pull_requests |
| route-action | commits |
| fetch-nonce | v2:83c3b34f-9315-0d4a-35df-b9ac0131e852 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BF84:1EFF29:207B0E2:2BE73DE:6A65588A |
| html-safe-nonce | 2bd93d77800f87923fa54456e7a6a89d5180262a8b24f57eb7b6ff1868942e37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjg0OjFFRkYyOToyMDdCMEUyOjJCRTczREU6NkE2NTU4OEEiLCJ2aXNpdG9yX2lkIjoiODY2OTAyODc5MTY1Nzc4MTM4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ff609fb19cedf04dba146c687f24ddefe7d35c0c27cf4013c0f3e0d3db1c35f4 |
| hovercard-subject-tag | pull_request:3283796011 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/plotly/plotly.py/pull/5508/commits/9bed9d301e2487a1b758a73c33c5861865995855 |
| twitter:image | https://avatars.githubusercontent.com/u/68575768?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/68575768?s=400&v=4 |
| og:image:alt | Summary When using add_vline, add_hline, add_vrect, or add_hrect with annotation_text on datetime axes, plotly crashes with a TypeError because the _mean() helper function tries to call float(sum(x... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/plotly/plotly.py git https://github.com/plotly/plotly.py.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 14579099 |
| octolytics-dimension-repository_nwo | plotly/plotly.py |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14579099 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.py |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 309153364422b3c499922d1a2a6404910a58ed8e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width