@@ -60,3 +60,36 @@ def test_series_duration_var_overflow() -> None:
6060 s = pl .Series ([timedelta (days = 10 ), timedelta (days = 20 ), timedelta (days = 40 )])
6161 with pytest .raises (PanicException , match = "OverflowError" ):
6262 s .var ()
63+
64+
65+ def test_series_duration_units () -> None :
66+ td = timedelta
67+
68+ assert_frame_equal (
69+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (x = pl .duration (weeks = pl .col ("x" ))),
70+ pl .DataFrame ({"x" : [td (weeks = i ) for i in range (4 )]}),
71+ )
72+ assert_frame_equal (
73+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (x = pl .duration (days = pl .col ("x" ))),
74+ pl .DataFrame ({"x" : [td (days = i ) for i in range (4 )]}),
75+ )
76+ assert_frame_equal (
77+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (x = pl .duration (hours = pl .col ("x" ))),
78+ pl .DataFrame ({"x" : [td (hours = i ) for i in range (4 )]}),
79+ )
80+ assert_frame_equal (
81+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (x = pl .duration (minutes = pl .col ("x" ))),
82+ pl .DataFrame ({"x" : [td (minutes = i ) for i in range (4 )]}),
83+ )
84+ assert_frame_equal (
85+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (
86+ x = pl .duration (milliseconds = pl .col ("x" ))
87+ ),
88+ pl .DataFrame ({"x" : [td (milliseconds = i ) for i in range (4 )]}),
89+ )
90+ assert_frame_equal (
91+ pl .DataFrame ({"x" : [0 , 1 , 2 , 3 ]}).select (
92+ x = pl .duration (microseconds = pl .col ("x" ))
93+ ),
94+ pl .DataFrame ({"x" : [td (microseconds = i ) for i in range (4 )]}),
95+ )
0 commit comments