Skip to content

Commit

Permalink
just parametrise over everything
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Oct 14, 2024
1 parent 9103a99 commit 0f8338b
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions py-polars/tests/unit/functions/range/test_datetime_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from datetime import date, datetime, timedelta
from typing import TYPE_CHECKING

import hypothesis.strategies as st
import pytest
from hypothesis import given, settings

import polars as pl
from polars.datatypes import DTYPE_TEMPORAL_UNITS
Expand Down Expand Up @@ -583,25 +581,22 @@ def test_datetime_range_specifying_ambiguous_11713() -> None:
assert_series_equal(result, expected)


@given(
closed=st.sampled_from(["none", "left", "right", "both"]),
time_unit=st.sampled_from(["ms", "us", "ns"]),
n=st.integers(1, 10),
unit=st.sampled_from(["s", "m", "h", "d", "mo"]),
start=st.datetimes(datetime(1965, 1, 1), datetime(2100, 1, 1)),
@pytest.mark.parametrize("closed", ["none", "left", "right", "both"])
@pytest.mark.parametrize("time_unit", ["ms", "us", "ns"])
@pytest.mark.parametrize("interval", ["1ms", "2s", "3h2s", "1d9s", "2mo"])
@pytest.mark.parametrize(
"start", [datetime(1960, 8, 3), datetime(1970, 1, 1), datetime(2100, 2, 5)]
)
@settings(max_examples=20)
@pytest.mark.benchmark
def test_datetime_range_fast_slow_paths(
closed: ClosedInterval, time_unit: TimeUnit, n: int, unit: str, start: datetime
closed: ClosedInterval, time_unit: TimeUnit, interval: str, start: datetime
) -> None:
end = pl.select(pl.lit(start).dt.offset_by(f"{n}{unit}")).item()
end = pl.select(pl.lit(start).dt.offset_by(interval)).item()
result_slow = pl.datetime_range(
start,
end,
closed=closed,
time_unit=time_unit,
interval=f"{n}{unit}",
interval=interval,
time_zone="Asia/Kathmandu",
eager=True,
).dt.replace_time_zone(None)
Expand All @@ -610,7 +605,7 @@ def test_datetime_range_fast_slow_paths(
end,
closed=closed,
time_unit=time_unit,
interval=f"{n}{unit}",
interval=interval,
eager=True,
)
assert_series_equal(result_slow, result_fast)

0 comments on commit 0f8338b

Please sign in to comment.