|
7 | 7 | import multiprocessing
|
8 | 8 | import subprocess
|
9 | 9 | import time
|
| 10 | +from datetime import timedelta |
10 | 11 | from typing import List
|
11 | 12 |
|
12 | 13 | import numpy as np
|
@@ -124,12 +125,16 @@ def test_various_dtypes(float_series):
|
124 | 125 | np.float64,
|
125 | 126 | ]
|
126 | 127 | for dtype in valid_dtype_list:
|
| 128 | + if np.issubdtype(dtype, np.unsignedinteger): |
| 129 | + fsv = float_series.astype("int").astype(dtype) |
| 130 | + else: |
| 131 | + fsv = float_series.astype(dtype) |
127 | 132 | fig = FigureResampler(go.Figure(), default_n_shown_samples=1000)
|
128 | 133 | # nb. datapoints > default_n_shown_samples
|
129 | 134 | fig.add_trace(
|
130 | 135 | go.Scatter(name="float_series"),
|
131 |
| - hf_x=float_series.index, |
132 |
| - hf_y=float_series.astype(dtype), |
| 136 | + hf_x=fsv.index, |
| 137 | + hf_y=fsv, |
133 | 138 | )
|
134 | 139 | fig.full_figure_for_development()
|
135 | 140 |
|
@@ -627,6 +632,50 @@ def test_set_hfx_tz_aware_series():
|
627 | 632 | assert all(fr.hf_data[0]["x"] == pd.DatetimeIndex(df.timestamp))
|
628 | 633 |
|
629 | 634 |
|
| 635 | +def test_tz_xaxis_range(): |
| 636 | + # test related to issue 212 - github.com/predict-idlab/plotly-resampler/issues/212 |
| 637 | + n = 50_000 |
| 638 | + s = pd.Series( |
| 639 | + index=pd.date_range("2020-01-01", periods=n, freq="1min", tz="UTC"), |
| 640 | + data=23 + np.random.randn(n), |
| 641 | + ) |
| 642 | + |
| 643 | + fig = go.Figure( |
| 644 | + layout=go.Layout( |
| 645 | + title=dict( |
| 646 | + text="AirT test timeseries", |
| 647 | + y=0.98, |
| 648 | + x=0.5, |
| 649 | + xanchor="center", |
| 650 | + yanchor="top", |
| 651 | + ), |
| 652 | + xaxis=dict(title="Time", type="date"), |
| 653 | + yaxis=dict(title="Air Temp (ºC)", range=[20, 30], fixedrange=True), |
| 654 | + template="seaborn", |
| 655 | + margin=dict(l=50, r=50, t=50, b=50, pad=5), |
| 656 | + showlegend=True, |
| 657 | + ) |
| 658 | + ) |
| 659 | + |
| 660 | + fr = FigureResampler(fig, verbose=True, default_n_shown_samples=2000) |
| 661 | + fr.add_trace(go.Scattergl(name="AirT", mode="markers"), hf_x=s.index, hf_y=s) |
| 662 | + fr.add_trace(go.Scattergl(name="AirT", mode="markers", x=s.index, y=s)) |
| 663 | + |
| 664 | + fr.add_vline(x=s.index[0]) |
| 665 | + fr.add_vline(x=s.index[-1]) |
| 666 | + |
| 667 | + start = s.index[0] - timedelta(hours=48) |
| 668 | + end = s.index[-1] + timedelta(hours=48) |
| 669 | + |
| 670 | + fr.update_xaxes(range=[start, end]) |
| 671 | + |
| 672 | + # verify whether the update was performed correctly |
| 673 | + out = fr.construct_update_data({"xaxis.range[0]": start, "xaxis.range[1]": end}) |
| 674 | + assert len(out) == 3 |
| 675 | + assert len(out[1]["x"]) == 2000 |
| 676 | + assert len(out[2]["x"]) == 2000 |
| 677 | + |
| 678 | + |
630 | 679 | def test_datetime_hf_x_no_index():
|
631 | 680 | df = pd.DataFrame(
|
632 | 681 | {"timestamp": pd.date_range("2020-01-01", "2020-01-02", freq="1s")}
|
|
0 commit comments