From 873197924ed909b1a1f3083a4b814e92897ee911 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sun, 1 Jan 2017 05:53:59 -0800 Subject: [PATCH] Deprecate vectorized div, rem/%, and mod methods for Dates.Periods. (#19802) --- base/dates/periods.jl | 5 +---- base/deprecated.jl | 6 ++++++ test/dates/periods.jl | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/base/dates/periods.jl b/base/dates/periods.jl index a37e8d48a7d6d..68e2d7e7c03d2 100644 --- a/base/dates/periods.jl +++ b/base/dates/periods.jl @@ -87,10 +87,7 @@ end *{P<:Period}(x::P,y::Real) = P(value(x) * Int64(y)) *(y::Real,x::Period) = x * y for (op,Ty,Tz) in ((:*,Real,:P), - (:/,:P,Float64), (:/,Real,:P), - (:div,:P,Int64), (:div,Integer,:P), - (:%,:P,:P), - (:mod,:P,:P)) + (:/,:P,Float64), (:/,Real,:P)) @eval begin function ($op){P<:Period}(X::StridedArray{P},y::$Ty) Z = similar(X, $Tz) diff --git a/base/deprecated.jl b/base/deprecated.jl index c60de606849ba..568332c4d35e1 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1438,6 +1438,12 @@ end @deprecate rem(A::Number, B::AbstractArray) rem.(A, B) @deprecate rem(A::AbstractArray, B::Number) rem.(A, B) +# Deprecate manually vectorized div, mod, and % methods for dates +@deprecate div{P<:Dates.Period}(X::StridedArray{P}, y::P) div.(X, y) +@deprecate div{P<:Dates.Period}(X::StridedArray{P}, y::Integer) div.(X, y) +@deprecate (%){P<:Dates.Period}(X::StridedArray{P}, y::P) X .% y +@deprecate mod{P<:Dates.Period}(X::StridedArray{P}, y::P) mod.(X, y) + # Deprecate manually vectorized mod methods in favor of compact broadcast syntax @deprecate mod(B::BitArray, x::Bool) mod.(B, x) @deprecate mod(x::Bool, B::BitArray) mod.(x, B) diff --git a/test/dates/periods.jl b/test/dates/periods.jl index f8802a35ede89..f50395822fead 100644 --- a/test/dates/periods.jl +++ b/test/dates/periods.jl @@ -35,8 +35,8 @@ t2 = Dates.Year(2) @test_throws MethodError ([t,t,t,t,t] .* Dates.Year(1)) == ([t,t,t,t,t]) @test ([t,t,t,t,t] * 1) == ([t,t,t,t,t]) @test ([t,t,t,t,t] .% t2) == ([t,t,t,t,t]) -@test div([t,t,t,t,t],Dates.Year(1)) == ([1,1,1,1,1]) -@test mod([t,t,t,t,t],Dates.Year(2)) == ([t,t,t,t,t]) +@test div.([t,t,t,t,t],Dates.Year(1)) == ([1,1,1,1,1]) +@test mod.([t,t,t,t,t],Dates.Year(2)) == ([t,t,t,t,t]) @test [t,t,t] / t2 == [0.5,0.5,0.5] @test abs(-t) == t