diff --git a/test/Core.jl b/test/Core.jl index e8375f00..d9e319d3 100644 --- a/test/Core.jl +++ b/test/Core.jl @@ -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) diff --git a/test/Numpy.jl b/test/Numpy.jl new file mode 100644 index 00000000..1d812106 --- /dev/null +++ b/test/Numpy.jl @@ -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 \ No newline at end of file