Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Mar 20, 2024
1 parent 5364f0f commit d1ad911
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions py-polars/polars/functions/as_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ def duration(
Number of microseconds.
nanoseconds
Number of nanoseconds.
time_unit : {'us', 'ms', 'ns'} or None
Time unit of the resulting expression, if no time unit is specified, and if nanosecond is specified,
then it will be set to `ns`. Otherwise, it will be set tu `us`.
time_unit : {None, 'us', 'ms', 'ns'}
Time unit of the resulting expression. If set to `None` (default), the time
unit will be inferred from the other inputs: `'ns'` if `nanoseconds` was
specified, `'us'` otherwise.
Returns
-------
Expand Down Expand Up @@ -303,7 +304,6 @@ def duration(
if time_unit is None:
time_unit = "ns"

# If the time unit wasn't set in one of the if-clauses then it is set to 'us'
if time_unit is None:
time_unit = "us"

Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,8 @@ def test_duration_arithmetic() -> None:
df = pl.DataFrame(
{"a": [datetime(2022, 1, 1, 0, 0, 0), datetime(2022, 1, 2, 0, 0, 0)]}
)
d1 = pl.duration(days=3, microseconds=987000, time_unit="us")
d2 = pl.duration(days=6, milliseconds=987, time_unit="us")
d1 = pl.duration(days=3, microseconds=987000)
d2 = pl.duration(days=6, milliseconds=987)

assert_frame_equal(
df.with_columns(
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/functions/as_datatype/test_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,9 @@ def test_duration_time_unit_us() -> None:
result = pl.duration(milliseconds=4, microseconds=3_000)
expected = pl.duration(milliseconds=4, microseconds=3_000, time_unit="us")
assert_frame_equal(pl.select(result), pl.select(expected))


def test_duration_time_unit_ms() -> None:
result = pl.duration(milliseconds=4)
expected = pl.duration(milliseconds=4, time_unit="us")
assert_frame_equal(pl.select(result), pl.select(expected))

0 comments on commit d1ad911

Please sign in to comment.