Skip to content

Commit 9dfc0dd

Browse files
Apply suggestions from code review
Co-authored-by: Miles Cranmer <[email protected]>
1 parent b3cc79f commit 9dfc0dd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Convert/numpy.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ function pydatetime64(
3636
end
3737
function 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...)
4242
end
4343
function 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)
4646
end
4747
export pydatetime64
4848

@@ -55,7 +55,7 @@ function pytimedelta64(
5555
))
5656
end
5757
function 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)
6161
end
@@ -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))
7575
end
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)
8484
end
8585

0 commit comments

Comments
 (0)