Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deprecations for non-broadcasted Dates arithmetic. #49832

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

inkydragon
Copy link
Member

fix #37814, replace #46093

@inkydragon inkydragon added dates Dates, times, and the Dates stdlib module deprecation This change introduces or involves a deprecation stdlib Julia's standard library labels May 16, 2023
Comment on lines 494 to 495
@test t2 - t1 == [Dates.Day(1) Dates.Day(31) Dates.Day(365); Dates.Day(365) Dates.Day(28) Dates.Day(1)]
@test t4 - t3 == [Dates.Millisecond(1000), Dates.Millisecond(60000), Dates.Millisecond(3600000)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> typeof(t1)
Matrix{Date} (alias for Array{Date, 2})

julia> typeof(t2)
Matrix{Date} (alias for Array{Date, 2})

julia> methods(-, (Matrix{Date},Matrix{Date}))
# 1 method for generic function "-" from Base:
 [1] -(A::AbstractArray, B::AbstractArray)
     @ arraymath.jl:6

Perhaps this usage is not deprecated.

@test_deprecated "use `x .- y` instead" t1 - Dates.Day(1)
@test_deprecated "use `x .- y` instead" t3 - Dates.Hour(1)
@test_deprecated "use `x .- y` instead" t1 - (Dates.Month(1) + Dates.Day(1))
@test_deprecated "use `x .- y` instead" t3 - (Dates.Hour(1) + Dates.Minute(1))
@test t2 - t1 == [Dates.Day(1) Dates.Day(31) Dates.Day(365); Dates.Day(365) Dates.Day(28) Dates.Day(1)]
@test t4 - t3 == [Dates.Millisecond(1000), Dates.Millisecond(60000), Dates.Millisecond(3600000)]
@test (Dates.Date(2009, 1, 1):Dates.Week(1):Dates.Date(2009, 1, 21)) - (Dates.Date(2009, 1, 1):Dates.Day(1):Dates.Date(2009, 1, 3)) == [Dates.Day(0), Dates.Day(6), Dates.Day(12)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> typeof((Dates.DateTime(2009, 1, 1, 1, 1, 1):Dates.Second(1):Dates.DateTime(2009, 1, 1, 1, 1, 3)))
StepRange{DateTime, Second}

julia> methods(-, (StepRange{DateTime, Second},StepRange{DateTime, Second}))
# 1 method for generic function "-" from Base:
 [1] -(x::OrdinalRange{T}, y::OrdinalRange{T}) where T<:TimeType
     @ Dates /mnt/v/julia/usr/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:95

# AbstractArray{TimeType}, AbstractArray{TimeType}
(-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)
(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = Vector(x) - Vector(y)

Perhaps this usage is not deprecated.

@@ -92,6 +92,7 @@ end

(*)(A::Period, B::AbstractArray) = Broadcast.broadcast_preserving_zero_d(*, A, B)
(*)(A::AbstractArray, B::Period) = Broadcast.broadcast_preserving_zero_d(*, A, B)
(/)(A::AbstractArray, B::Period) = Broadcast.broadcast_preserving_zero_d(/, A, B)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't actually be deprecated, see #34786 (which tests this).

Originally posted by @fredrikekre in #46093 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module deprecation This change introduces or involves a deprecation stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dates + works on array of Dates and a single Date
2 participants