Skip to content

Commit

Permalink
Deprecate vectorized div, rem/%, and mod methods for Dates.Periods. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 authored and tkelman committed Jan 1, 2017
1 parent 35d1780 commit 8731979
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions base/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/dates/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8731979

Please sign in to comment.