diff --git a/plotly/shapeannotation.py b/plotly/shapeannotation.py index a2323ed02d4..085b4fd8810 100644 --- a/plotly/shapeannotation.py +++ b/plotly/shapeannotation.py @@ -4,6 +4,9 @@ def _mean(x): if len(x) == 0: raise ValueError("x must have positive length") + + if len(x) == 2 and x[0] == x[1]: + return x[0] return float(sum(x)) / len(x) diff --git a/tests/test_optional/test_autoshapes/test_annotated_shapes.py b/tests/test_optional/test_autoshapes/test_annotated_shapes.py index 8d7c3806991..dfef857288b 100644 --- a/tests/test_optional/test_autoshapes/test_annotated_shapes.py +++ b/tests/test_optional/test_autoshapes/test_annotated_shapes.py @@ -52,6 +52,28 @@ def multi_plot_fixture(): return fig +from datetime import datetime, timedelta + + +def test_add_shape_with_dates(): + start_date = datetime(2025, 1, 1) + end_date = datetime(2025, 10, 10) + dates = [] + current_date = start_date + while current_date <= end_date: + dates.append(current_date.strftime("%Y-%m-%d")) + current_date += timedelta(weeks=4) + print(dates) + fig = go.Figure( + data=[go.Scatter(x=[x for x in range(1, 20, 2)], y=dates)], + layout=go.Layout( + title=go.layout.Title(text="A Figure Specified By A Graph Object") + ), + ) + fig.add_vline(x="2025-06-24", annotation_text="test") + assert len(fig.layout.annotations) == 1 + + # Make sure adding a shape without specifying an annotation doesn't add any annotations def test_add_shape_no_annotation(multi_plot_fixture): multi_plot_fixture.add_hline(y=2, row="all", col="all") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy