Skip to content

Commit 66459c6

Browse files
committed
add tests for pytimedelta64, pydatetime64
1 parent d36c113 commit 66459c6

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

test/Core.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,6 @@ end
676676

677677
@testitem "datetime" begin
678678
using Dates
679-
using CondaPkg
680-
CondaPkg.add("numpy")
681-
682679
dt = pyimport("datetime")
683680
x1 = pydate(2001, 2, 3)
684681
@test pyisinstance(x1, dt.date)

test/Numpy.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@testitem "timedelta64" begin
2+
using Dates
3+
using CondaPkg
4+
CondaPkg.add("numpy")
5+
6+
td = pyimport("numpy").timedelta64
7+
@testset for x in [
8+
-1_000_000_000,
9+
-1_000_000,
10+
-1_000,
11+
-1,
12+
0,
13+
1,
14+
1_000,
15+
1_000_000,
16+
1_000_000_000,
17+
], (Unit, unit, pyunit) in [
18+
(Nanosecond, :nanoseconds, :ns),
19+
(Microsecond, :microseconds, :us),
20+
(Millisecond, :milliseconds, :ms),
21+
(Second, :seconds, :s),
22+
(Minute, :minutes, :m),
23+
(Hour, :hours, :h),
24+
(Day, :days, :D),
25+
(Week, :weeks, :W),
26+
(Month, :months, :M),
27+
(Year, :years, :Y),
28+
]
29+
y = pytimedelta64(; [unit => x]...)
30+
y2 = pytimedelta64(Unit(x))
31+
@test pyeq(Bool, y, y2)
32+
@test pyeq(Bool, y, td(x, "$pyunit"))
33+
end
34+
end
35+
36+
@testitem "datetime64" begin
37+
using Dates
38+
using CondaPkg
39+
CondaPkg.add("numpy")
40+
41+
y = 2024
42+
m = 2
43+
d = 29
44+
h = 23
45+
min = 59
46+
s = 58
47+
ms = 999
48+
us = 998
49+
ns = 997
50+
51+
date = DateTime(y, m, d, h, min, s, ms)
52+
pydate = pydatetime64(date)
53+
pydate2 = pydatetime64(year = y, month = m, day = d, hour = h, minute = min, second = s, millisecond = ms)
54+
dt = date - Second(0)
55+
pydate3 = pydatetime64(dt)
56+
@test pyeq(Bool, pydate, pydate2)
57+
end

0 commit comments

Comments
 (0)