Skip to content

Commit

Permalink
python: fix time conversion (#3851)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 29, 2022
1 parent 3a94185 commit 539043a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions py-polars/polars/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def _to_python_time(value: int) -> time:
seconds = (microsecond // 1000_000) % 60
minutes = (microsecond // (1000_000 * 60)) % 60
hours = (microsecond // (1000_000 * 60 * 60)) % 24

microsecond = microsecond % seconds * 1000_000
microsecond = microsecond - (seconds + minutes * 60 + hours * 3600) * 1000_000

return time(hour=hours, minute=minutes, second=seconds, microsecond=microsecond)

Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/test_datelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,9 @@ def test_sorted_unique() -> None:

def test_time_zero_3828() -> None:
assert pl.Series(values=[time(0)], dtype=pl.Time).to_list() == [time(0)]


def test_time_microseconds_3843() -> None:
in_val = [time(0, 9, 11, 558332)]
s = pl.Series(in_val)
assert s.to_list() == in_val

0 comments on commit 539043a

Please sign in to comment.