Skip to content

Commit 02d4401

Browse files
committed
✨ fix some pandas tests + test for #212
1 parent b7c40db commit 02d4401

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

plotly_resampler/aggregation/plotly_aggregator_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def to_same_tz(
3838
return None
3939
elif reference_tz is not None:
4040
if ts.tz is not None:
41-
assert ts.tz.zone == reference_tz.zone
41+
assert ts.tz.__str__() == reference_tz.__str__()
4242
return ts
4343
else: # localize -> time remains the same
4444
return ts.tz_localize(reference_tz)

tests/test_figure_resampler.py

+51-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pytest
1616
from plotly.subplots import make_subplots
1717
from selenium.webdriver.common.by import By
18+
from datetime import timedelta
1819

1920
from plotly_resampler import LTTB, EveryNthPoint, FigureResampler
2021
from plotly_resampler.aggregation import NoGapHandler, PlotlyAggregatorParser
@@ -124,12 +125,16 @@ def test_various_dtypes(float_series):
124125
np.float64,
125126
]
126127
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)
127132
fig = FigureResampler(go.Figure(), default_n_shown_samples=1000)
128133
# nb. datapoints > default_n_shown_samples
129134
fig.add_trace(
130135
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,
133138
)
134139
fig.full_figure_for_development()
135140

@@ -627,6 +632,50 @@ def test_set_hfx_tz_aware_series():
627632
assert all(fr.hf_data[0]["x"] == pd.DatetimeIndex(df.timestamp))
628633

629634

635+
def test_tz_xaxis_range():
636+
# test related to the followign issue:
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=f"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+
630679
def test_datetime_hf_x_no_index():
631680
df = pd.DataFrame(
632681
{"timestamp": pd.date_range("2020-01-01", "2020-01-02", freq="1s")}

0 commit comments

Comments
 (0)