Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plotly_resampler/aggregation/plotly_aggregator_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def get_start_end_indices(hf_trace_data, axis_type, start, end) -> Tuple[int, in
# Search the index-positions
start_idx = bisect.bisect_left(hf_trace_data["x"], start)
end_idx = bisect.bisect_right(hf_trace_data["x"], end)
start_idx = max(0, start_idx - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should certainly add some documentation / issue reference to which this is performed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to CHANGELOG.md. Do I need to mention it anywhere else?

end_idx = min(end_idx + 1, len(hf_trace_data["x"]))
return start_idx, end_idx

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions tests/test_figure_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def test_log_axis():
assert len(out) == 2
assert (x1 - x0) < 10
assert len(out[1]["x"]) == 1000
assert out[-1]["x"][0] >= 100
assert out[-1]["x"][0] >= 99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here, you increase (i.e. lower) the left boundary, because (when possible) a datapoint to the left is added. Why is there no need to increase the right boundary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(maybe because of a small rounding error with log?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right!
-> end_idx = bisect.bisect_right(hf_trace_data["x"], end)
-> end == 49999.99999999999

Nevertheless alter boundary. It would benefit readability

assert out[-1]["x"][-1] <= 50_000


Expand Down Expand Up @@ -997,8 +997,8 @@ def test_time_tz_slicing():
start_idx, end_idx = PlotlyAggregatorParser.get_start_end_indices(
hf_data_dict, hf_data_dict["axis_type"], t_start, t_stop
)
assert (s.index[start_idx] - t_start) <= pd.Timedelta(seconds=1)
assert (s.index[min(end_idx, n - 1)] - t_stop) <= pd.Timedelta(seconds=1)
assert (s.index[start_idx] - t_start) <= pd.Timedelta(seconds=2)
assert (s.index[min(end_idx, n - 1)] - t_stop) <= pd.Timedelta(seconds=2)


def test_time_tz_slicing_different_timestamp():
Expand Down Expand Up @@ -1064,10 +1064,10 @@ def test_different_tz_no_tz_series_slicing():
)
assert (
s.tz_localize(None).index[start_idx].tz_localize(t_start.tz) - t_start
) <= pd.Timedelta(seconds=1)
) <= pd.Timedelta(seconds=2)
assert (
s.tz_localize(None).index[end_idx].tz_localize(t_stop.tz) - t_stop
) <= pd.Timedelta(seconds=1)
) <= pd.Timedelta(seconds=2)


def test_multiple_tz_no_tz_series_slicing():
Expand Down
14 changes: 7 additions & 7 deletions tests/test_figurewidget_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def test_hf_data_property_reload_data():
assert np.all(fwr.hf_data[0]["y"] == new_y)

fwr.reload_data()
assert (fwr.data[0]["x"][0] >= 10_000) & (fwr.data[0]["x"][-1] <= 20_000)
assert (fwr.data[0]["x"][0] >= 9_999) & (fwr.data[0]["x"][-1] <= 20_001)
assert np.all(fwr.data[0]["y"] == new_y[fwr.data[0]["x"]])
assert (fwr.layout["yaxis"].range[0] == -20) & (fwr.layout["yaxis"].range[-1] == 3)

Expand Down Expand Up @@ -869,8 +869,8 @@ def test_hf_data_property_subplots_reload_data():
assert np.all(fwr.hf_data[0]["y"] == new_y)

fwr.reload_data()
assert (fwr.data[0]["x"][0] >= 10_000) & (fwr.data[0]["x"][-1] <= 20_000)
assert (fwr.data[1]["x"][0] >= 40_000) & (fwr.data[1]["x"][-1] <= 60_000)
assert (fwr.data[0]["x"][0] >= 9_999) & (fwr.data[0]["x"][-1] <= 20_001)
assert (fwr.data[1]["x"][0] >= 39_999) & (fwr.data[1]["x"][-1] <= 60_001)
assert np.all(fwr.data[0]["y"] == new_y[fwr.data[0]["x"]])
assert np.all(fwr.data[1]["y"] == new_y[fwr.data[1]["x"]])
assert (fwr.layout["yaxis"].range[0] == -20) & (fwr.layout["yaxis"].range[-1] == 3)
Expand Down Expand Up @@ -900,8 +900,8 @@ def test_hf_data_subplots_non_shared_xaxes():
assert 0 <= x_0[0] <= (n / 1000)
assert (n - 1000) <= x_0[-1] <= n - 1
x_1 = fwr.data[1]["x"]
assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000)
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000
assert 39_999 <= x_1[0] <= 40_001 + (20_000 / 1000)
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_001


def test_hf_data_subplots_non_shared_xaxes_row_col_none():
Expand All @@ -925,8 +925,8 @@ def test_hf_data_subplots_non_shared_xaxes_row_col_none():
assert 0 <= x_0[0] <= (n / 1000)
assert (n - 1000) <= x_0[-1] <= n - 1
x_1 = fwr.data[1]["x"]
assert 40_000 <= x_1[0] <= 40_000 + (20_000 / 1000)
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_000
assert 39_999 <= x_1[0] <= 40_001 + (20_000 / 1000)
assert (60_000 - 20_000 / 1_000) <= x_1[-1] <= 60_001


def test_updates_two_traces():
Expand Down