From 3148bae9cca01a6d580c8ffc70b9d1ec49ea6f3a Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 21 Jan 2025 17:52:20 +0100 Subject: [PATCH] specialize Base.convert(::<:Period, CompoundPeriod) for julia < 1.8 --- src/Convert/Convert.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Convert/Convert.jl b/src/Convert/Convert.jl index e3145d58..8e97c55d 100644 --- a/src/Convert/Convert.jl +++ b/src/Convert/Convert.jl @@ -51,8 +51,9 @@ import ..Core: pyconvert # patch conversion to Period types for julia <= 1.7 @static if VERSION < v"1.8.0-" - Base.convert(::Type{T}, x::CompoundPeriod) where T<:Period = - isconcretetype(T) ? sum(T, x.periods; init = zero(T)) : throw(MethodError(convert,(T,x))) + for T in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond, :Microsecond, :Nanosecond) + @eval Base.convert(::Type{$T}, x::CompoundPeriod) = sum($T, x.periods; init = zero($T)) + end end include("pyconvert.jl")