@@ -36,13 +36,13 @@ function pydatetime64(
3636end
3737function pydatetime64 (@nospecialize (x:: T )) where T <: Period
3838 T <: Union{Week, Day, Hour, Minute, Second, Millisecond, Microsecond} ||
39- error (" Unsupported Period type: " , " Year, Month and Nanosecond are not supported, consider using pytimedelta64 instead." )
40- args = T .== (Day, Second, Millisecond, Microsecond, Minute, Hour, Week)
39+ error (" Unsupported Period type: ` $x :: $T `. Consider using pytimedelta64 instead." )
40+ args = map (Base . Fix1 (isa, x), (Day, Second, Millisecond, Microsecond, Minute, Hour, Week) )
4141 pydatetime64 (x. value .* args... )
4242end
4343function pydatetime64 (x:: CompoundPeriod )
4444 x = canonicalize (x)
45- isempty (x. periods) ? pydatetime64 (Second (0 )) : sum (pydatetime64 .( x. periods) )
45+ isempty (x. periods) ? pydatetime64 (Second (0 )) : sum (pydatetime64, x. periods)
4646end
4747export pydatetime64
4848
@@ -55,7 +55,7 @@ function pytimedelta64(
5555 ))
5656end
5757function pytimedelta64 (@nospecialize (x:: T )) where T <: Period
58- index = findfirst (== (T), (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, T))
58+ index = findfirst (== (T), (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, T)):: Int
5959 unit = (" Y" , " M" , " W" , " D" , " h" , " m" , " s" , " ms" , " us" , " ns" , " " )[index]
6060 pyimport (" numpy" ). timedelta64 (x. value, unit)
6161end
@@ -70,7 +70,7 @@ function pyconvert_rule_datetime64(::Type{DateTime}, x::Py)
7070 value = reinterpret (Int64, pyconvert (Vector, x))[1 ]
7171 units = (" Y" , " M" , " W" , " D" , " h" , " m" , " s" , " ms" , " us" , " ns" )
7272 types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
73- T = types[findfirst (== (unit), units)]
73+ T = types[findfirst (== (unit), units):: Int ]
7474 pyconvert_return (DateTime (_base_datetime) + T (value * count))
7575end
7676
@@ -79,7 +79,7 @@ function pyconvert_rule_timedelta64(::Type{CompoundPeriod}, x::Py)
7979 value = reinterpret (Int64, pyconvert (Vector, x))[1 ]
8080 units = (" Y" , " M" , " W" , " D" , " h" , " m" , " s" , " ms" , " us" , " ns" )
8181 types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
82- T = types[findfirst (== (unit), units)]
82+ T = types[findfirst (== (unit), units):: Int ]
8383 pyconvert_return (CompoundPeriod (T (value * count)) |> canonicalize)
8484end
8585
0 commit comments