Skip to content

Commit

Permalink
chore: fixup failing test due to offset deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Apr 13, 2024
1 parent 8547d86 commit a85347d
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions py-polars/tests/unit/datatypes/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from polars.type_aliases import (
Ambiguous,
FillNullStrategy,
PolarsIntegerType,
PolarsTemporalType,
TimeUnit,
)
Expand Down Expand Up @@ -772,39 +773,29 @@ def test_upsample_time_zones(


@pytest.mark.parametrize(
("every", "offset", "fill", "expected_index", "expected_groups"),
("every", "fill", "expected_index", "expected_groups"),
[
(
"1i",
"0i",
"forward",
[1, 2, 3, 4] + [5, 6, 7],
["a"] * 4 + ["b"] * 3,
),
(
"1i",
"0h",
"forward",
"backward",
[1, 2, 3, 4] + [5, 6, 7],
["a"] * 4 + ["b"] * 3,
),
(
"1i",
"1i",
"backward",
[2, 3, 4] + [6, 7],
["a"] * 3 + ["b"] * 2,
),
],
)
@pytest.mark.parametrize("dtype", [pl.Int32, pl.Int64, pl.UInt32, pl.UInt64])
def test_upsample_index(
every: str,
offset: str,
fill: FillNullStrategy | None,
expected_index: list[int],
expected_groups: list[str],
dtype: pl.datatypes.DataTypeClass,
dtype: PolarsIntegerType,
) -> None:
df = (
pl.DataFrame(
Expand All @@ -823,51 +814,49 @@ def test_upsample_index(
}
).with_columns(pl.col("index").cast(dtype))
result = (
df.upsample(time_column="index", group_by="groups", every=every, offset=offset)
df.upsample(time_column="index", group_by="groups", every=every)
.fill_null(strategy=fill)
.sort(["groups", "index"])
)
assert_frame_equal(result, expected)


@pytest.mark.parametrize(
("every", "offset", "fill"),
("every", "offset"),
[
(
"1i",
"1h",
"forward",
),
(
"1h",
"1i",
"forward",
),
(
"1h",
"0i",
"forward",
),
(
"0i",
"1h",
"forward",
),
],
)
def test_upsample_index_invalid(
df: pl.DataFrame,
every: str,
offset: str,
fill: FillNullStrategy | None,
) -> None:
df = pl.DataFrame(
{
"index": [1, 2, 4] + [5, 7],
"groups": ["a"] * 3 + ["b"] * 2,
}
).set_sorted("index")
with pytest.raises(ComputeError, match=r"cannot combine time .* integer"):
with (
pytest.raises(ComputeError, match=r"cannot combine time .* integer"),
pytest.deprecated_call(),
):
df.upsample(time_column="index", every=every, offset=offset)


Expand Down

0 comments on commit a85347d

Please sign in to comment.