Skip to content

Commit

Permalink
fix: Separate temporal tests (pola-rs#19012)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller authored Sep 30, 2024
1 parent c23266b commit e402e70
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions py-polars/tests/unit/functions/test_lit.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,37 @@ def test_lit_decimal_parametric(s: pl.Series) -> None:
assert result == value


@pytest.mark.parametrize(
("dt_class", "input"),
[
(date, (2024, 1, 1)),
(datetime, (2024, 1, 1)),
(timedelta, (1,)),
(time, (1,)),
],
)
def test_lit_temporal_subclass_w_allow_object(
dt_class: type, input: tuple[int]
) -> None:
class MyClass(dt_class): # type: ignore[misc]
def test_lit_date_subclass() -> None:
class SubDate(date):
pass

result = pl.select(a=pl.lit(SubDate(2024, 1, 1)))
expected = pl.DataFrame({"a": [date(2024, 1, 1)]})
assert_frame_equal(result, expected)


def test_lit_datetime_subclass() -> None:
class SubDatetime(datetime):
pass

result = pl.select(a=pl.lit(SubDatetime(2024, 1, 1)))
expected = pl.DataFrame({"a": [datetime(2024, 1, 1)]})
assert_frame_equal(result, expected)


def test_lit_time_subclass() -> None:
class SubTime(time):
pass

result = pl.select(a=pl.lit(SubTime(1)))
expected = pl.DataFrame({"a": [time(1)]})
assert_frame_equal(result, expected)


def test_lit_timedelta_subclass() -> None:
class SubTimedelta(timedelta):
pass

result = pl.select(a=pl.lit(MyClass(*input)))
expected = pl.DataFrame({"a": [dt_class(*input)]})
result = pl.select(a=pl.lit(SubTimedelta(1)))
expected = pl.DataFrame({"a": [timedelta(1)]})
assert_frame_equal(result, expected)

0 comments on commit e402e70

Please sign in to comment.