Skip to content

Commit

Permalink
deprecate vectorized methods hiding in Dates (#23207)
Browse files Browse the repository at this point in the history
* Deprecate vectorized DateTime methods in favor of compact broadcast syntax.

* Deprecate vectorized Date methods in favor of compact broadcast syntax.

* Deprecate vectorized Dates.format methods in favor of compact broadcast syntax.

* Change a few Dates tests to use the dateformat string macro.
  • Loading branch information
Sacha0 authored and quinnj committed Aug 12, 2017
1 parent eabd021 commit e4bb6d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ Deprecated or removed
* Calling `union` with no arguments is deprecated; construct an empty set with an appropriate
element type using `Set{T}()` instead ([#23144]).

* Vectorized `DateTime`, `Date`, and `format` methods have been deprecated in favor of
dot-syntax ([#23207]).

* `Base.cpad` has been removed; use an appropriate combination of `rpad` and `lpad`
instead ([#23187]).

Expand Down Expand Up @@ -1160,3 +1163,5 @@ Command-line option changes
[#23117]: https://github.com/JuliaLang/julia/issues/23117
[#23144]: https://github.com/JuliaLang/julia/issues/23144
[#23157]: https://github.com/JuliaLang/julia/issues/23157
[#23187]: https://github.com/JuliaLang/julia/issues/23187
[#23207]: https://github.com/JuliaLang/julia/issues/23207
21 changes: 0 additions & 21 deletions base/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,24 +557,3 @@ function Base.string(dt::Date)
dd = lpad(d, 2, "0")
return "$yy-$mm-$dd"
end

# vectorized
function DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH)
DateTime(Y, DateFormat(f, locale))
end
function DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat)
return reshape(DateTime[parse(DateTime, y, df) for y in Y], size(Y))
end
function Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH)
Date(Y, DateFormat(f, locale))
end
function Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat)
return reshape(Date[Date(parse(Date, y, df)) for y in Y], size(Y))
end

function format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH)
format(Y, DateFormat(f, locale))
end
function format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where T<:TimeType
return reshape([format(y, df) for y in Y], size(Y))
end
20 changes: 20 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,26 @@ for op in (:exp, :exp2, :exp10, :log, :log2, :log10,
@eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x)
end

# deprecate remaining vectorized methods from Base.Dates
@eval Dates @deprecate(
DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH),
DateTime.(Y, f; locale=locale) )
@eval Dates @deprecate(
DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat),
DateTime.(Y, df) )
@eval Dates @deprecate(
Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH),
Date.(Y, f; locale=locale) )
@eval Dates @deprecate(
Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat),
Date.(Y, df) )
@eval Dates @deprecate(
format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH),
format.(Y, f; locale=locale) )
@eval Dates @deprecate(
format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where {T<:TimeType},
format.(Y, df) )

# PR #22182
@deprecate is_apple Sys.isapple
@deprecate is_bsd Sys.isbsd
Expand Down
13 changes: 6 additions & 7 deletions test/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,18 @@ f = "ymd"
@test Dates.Date(string(Dates.Date(dt))) == Dates.Date(dt)
@test Dates.DateTime(string(dt)) == dt

# Vectorized
# formerly vectorized Date/DateTime/format methods
dr = ["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05",
"2000-01-06", "2000-01-07", "2000-01-08", "2000-01-09", "2000-01-10"]
dr2 = [Dates.Date(2000) : Dates.Date(2000, 1, 10);]
@test Dates.Date(dr) == dr2
@test Dates.Date(dr, "yyyy-mm-dd") == dr2
@test Dates.Date.(dr) == dr2
@test Dates.Date.(dr, dateformat"yyyy-mm-dd") == dr2
@test Dates.DateTime.(dr) == Dates.DateTime.(dr2)
@test Dates.DateTime(dr, "yyyy-mm-dd") == Dates.DateTime.(dr2)
@test Dates.DateTime.(dr, dateformat"yyyy-mm-dd") == Dates.DateTime.(dr2)

@test Dates.format(dr2) == dr
@test Dates.format(dr2, "yyyy-mm-dd") == dr
@test Dates.format.(dr2, "yyyy-mm-dd") == dr

@test typeof(Dates.Date(dr)) == Array{Date, 1}
@test typeof(Dates.Date.(dr)) == Array{Date, 1}

# Issue 13
t = Dates.DateTime(1, 1, 1, 14, 51, 0, 118)
Expand Down

0 comments on commit e4bb6d7

Please sign in to comment.