Skip to content

Commit fac1ef8

Browse files
author
hhaensel
committed
add tests for timedelta64 canonicalize
1 parent 3c51b54 commit fac1ef8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/Numpy.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
CondaPkg.add("numpy")
55

66
td = pyimport("numpy").timedelta64
7+
get_unit(x) = pyconvert(String, pyimport("numpy").datetime_data(x)[0])
78
@testset for x in [
89
-1_000_000_000,
910
-1_000_000,
@@ -30,7 +31,18 @@
3031
y2 = pytimedelta64(Unit(x))
3132
@test pyeq(Bool, y, y2)
3233
@test pyeq(Bool, y, td(x, "$pyunit"))
34+
@test get_unit(y) == "$pyunit"
35+
@test get_unit(y2) == "$pyunit"
3336
end
37+
x = pytimedelta64(Second(60))
38+
@test get_unit(x) == "s"
39+
x = pytimedelta64(Second(60); canonicalize = true)
40+
@test get_unit(x) == "m"
41+
42+
PythonCall.Convert.CANONICALIZE_TIMEDELTA64[] = true
43+
@test pyconvert(Dates.CompoundPeriod, pytimedelta64(Second(60)),).periods[1] isa Minute
44+
PythonCall.Convert.CANONICALIZE_TIMEDELTA64[] = false
45+
@test pyconvert(Dates.CompoundPeriod, pytimedelta64(Second(60)),).periods[1] isa Second
3446
end
3547

3648
@testitem "datetime64" begin

0 commit comments

Comments
 (0)