Skip to content

Commit

Permalink
add tests for pytimedelta64, pydatetime64
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 21, 2025
1 parent d36c113 commit 66459c6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
3 changes: 0 additions & 3 deletions test/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,6 @@ end

@testitem "datetime" begin
using Dates
using CondaPkg
CondaPkg.add("numpy")

dt = pyimport("datetime")
x1 = pydate(2001, 2, 3)
@test pyisinstance(x1, dt.date)
Expand Down
57 changes: 57 additions & 0 deletions test/Numpy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@testitem "timedelta64" begin
using Dates
using CondaPkg
CondaPkg.add("numpy")

td = pyimport("numpy").timedelta64
@testset for x in [
-1_000_000_000,
-1_000_000,
-1_000,
-1,
0,
1,
1_000,
1_000_000,
1_000_000_000,
], (Unit, unit, pyunit) in [
(Nanosecond, :nanoseconds, :ns),
(Microsecond, :microseconds, :us),
(Millisecond, :milliseconds, :ms),
(Second, :seconds, :s),
(Minute, :minutes, :m),
(Hour, :hours, :h),
(Day, :days, :D),
(Week, :weeks, :W),
(Month, :months, :M),
(Year, :years, :Y),
]
y = pytimedelta64(; [unit => x]...)
y2 = pytimedelta64(Unit(x))
@test pyeq(Bool, y, y2)
@test pyeq(Bool, y, td(x, "$pyunit"))
end
end

@testitem "datetime64" begin
using Dates
using CondaPkg
CondaPkg.add("numpy")

y = 2024
m = 2
d = 29
h = 23
min = 59
s = 58
ms = 999
us = 998
ns = 997

date = DateTime(y, m, d, h, min, s, ms)
pydate = pydatetime64(date)
pydate2 = pydatetime64(year = y, month = m, day = d, hour = h, minute = min, second = s, millisecond = ms)
dt = date - Second(0)
pydate3 = pydatetime64(dt)
@test pyeq(Bool, pydate, pydate2)
end

0 comments on commit 66459c6

Please sign in to comment.