Skip to content

Commit

Permalink
add test to compare datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
samster25 committed Dec 16, 2023
1 parent b69c6df commit 7a154c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/series/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,13 @@ def test_series_cast_struct_add_col() -> None:


def test_cast_date_to_timestamp():
from datetime import date
from datetime import date, datetime

import pytz

input = Series.from_pylist([date(2022, 1, 6)])
casted = input.cast(DataType.timestamp("us", "UTC"))
# DO ASSERT AS TIMESTAMP
assert casted.to_pylist() == [datetime(2022, 1, 6, tzinfo=pytz.utc)]

back = casted.dt.date()
assert (input == back).to_pylist() == [True]
6 changes: 6 additions & 0 deletions tests/series/test_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ def test_compare_lt_timestamps_tz_date():
assert (tz1 < tz2).to_pylist() == [True]


def test_compare_lt_timestamps_tz_date_same():
tz1 = Series.from_pylist([datetime(2022, 1, 6, tzinfo=pytz.utc)])
tz2 = Series.from_pylist([date(2022, 1, 6)])
assert (tz1 < tz2).to_pylist() == [False]


@pytest.mark.parametrize("tu1, tu2", itertools.product(["ns", "us", "ms"], repeat=2))
def test_compare_timestamps_same_tz(tu1, tu2):
tz1 = Series.from_pylist([datetime(2022, 1, 1, tzinfo=pytz.utc)]).cast(DataType.timestamp(tu1, "UTC"))
Expand Down

0 comments on commit 7a154c6

Please sign in to comment.