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

Drop all v1 deprecations for v2 #214

Open
wants to merge 6 commits into
base: v2-DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 2 additions & 199 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,202 +1,5 @@
using Base: @deprecate, depwarn
import Dates: Date, DateTime

# BEGIN Intervals 1.X.Y deprecations
# BEGIN Intervals 2.X.Y deprecations

export Inclusivity, inclusivity
include("inclusivity.jl")

@deprecate Date(interval::Interval{Date}) convert(Date, interval)
@deprecate DateTime(interval::Interval{DateTime}) convert(DateTime, interval)
@deprecate Date(interval::AnchoredInterval{P, Date} where P) convert(Date, interval)
@deprecate DateTime(interval::AnchoredInterval{P, DateTime} where P) convert(DateTime, interval)


function Endpoint{T,D}(ep::T, included::Bool) where {T,D}
B = bound_type(included)
depwarn("`Endpoint{T,D}(ep, $included)` is deprecated, use `Endpoint{T,D,$(repr(B))}(ep)` instead.", :Endpoint)
return Endpoint{T,D,B}(ep)
end

function LeftEndpoint(ep, included::Bool)
B = bound_type(included)
depwarn("`LeftEndpoint(ep, $included)` is deprecated, use `LeftEndpoint{$(repr(B))}(ep)` instead.", :LeftEndpoint)
return LeftEndpoint{B}(ep)
end

function RightEndpoint(ep, included::Bool)
B = bound_type(included)
depwarn("`RightEndpoint(ep, $included)` is deprecated, use `RightEndpoint{$(repr(B))}(ep)` instead.", :RightEndpoint)
return RightEndpoint{B}(ep)
end

# intervals.jl
function Interval{T,L,R}(f::T, l::T, inc::Inclusivity) where {T,L,R}
left_inc = bound_type(first(inc))
right_inc = bound_type(last(inc))
if L !== left_inc || R !== right_inc
throw(ArgumentError("Specified inclusivity ($(repr(left_inc)), $(repr(right_inc))) doesn't match bound types ($(repr(L)), $(repr(R)))"))
end
depwarn("`Interval{T,$(repr(L)),$(repr(R))}(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval)
return Interval{T,L,R}(f, l)
end

function Interval{T,L,R}(f, l, inc::Inclusivity) where {T,L,R}
# Using depwarn from next call
return Interval{T,L,R}(convert(T, f), convert(T, l), inc)
end

function Interval{T}(f, l, inc::Inclusivity) where T
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`Interval{T}(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval)
return Interval{T,L,R}(f, l)
end

function Interval{T}(f, l, x::Bool, y::Bool) where T
L = bound_type(x)
R = bound_type(y)
depwarn("`Interval{T}(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval)
return Interval{T,L,R}(f, l)
end

function Interval(f, l, inc::Inclusivity)
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`Interval(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval)
return Interval{L,R}(f, l)
end

function Interval(f, l, x::Bool, y::Bool)
L = bound_type(x)
R = bound_type(y)
depwarn("`Interval(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval)
return Interval{L,R}(f, l)
end

function inclusivity(interval::AbstractInterval{T,L,R}) where {T,L,R}
depwarn("`inclusivity(interval)` is deprecated and has no direct replacement. See `bounds_types(interval)` for similar functionality.", :inclusivity)
return Inclusivity(L === Closed, R === Closed; ignore_depwarn=true)
end

# anchoredintervals.jl
function AnchoredInterval{P,T,L,R}(anchor::T, inc::Inclusivity) where {P,T,L,R}
left_inc = bound_type(first(inc))
right_inc = bound_type(last(inc))
if L !== left_inc || R !== right_inc
throw(ArgumentError("Specified inclusivity ($(repr(left_inc)), $(repr(right_inc))) doesn't match bound types ($(repr(L)), $(repr(R)))"))
end
depwarn("`AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval)
return AnchoredInterval{P,T,L,R}(anchor)
end

function AnchoredInterval{P,T,L,R}(anchor, inc::Inclusivity) where {P,T,L,R}
# Using depwarn from next call
return AnchoredInterval{P,T,L,R}(convert(T, anchor), inc)
end

function AnchoredInterval{P,T}(anchor, inc::Inclusivity) where {P,T}
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`AnchoredInterval{P,T}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval)
return AnchoredInterval{P,T,L,R}(anchor)
end

function AnchoredInterval{P,T}(anchor, x::Bool, y::Bool) where {P,T}
L = bound_type(x)
R = bound_type(y)
depwarn("`AnchoredInterval{P,T}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval)
return AnchoredInterval{P,T,L,R}(anchor)
end

function AnchoredInterval{P}(anchor, inc::Inclusivity) where P
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`AnchoredInterval{P}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval)
return AnchoredInterval{P,L,R}(anchor)
end

function AnchoredInterval{P}(anchor, x::Bool, y::Bool) where P
L = bound_type(x)
R = bound_type(y)
depwarn("`AnchoredInterval{P}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval)
return AnchoredInterval{P,L,R}(anchor)
end

function HourEnding(anchor, x::Bool, y::Bool)
L = bound_type(x)
R = bound_type(y)
depwarn("`HourEnding(anchor, $x, $y)` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding)
return HourEnding{L,R}(anchor)
end

function HourEnding(anchor, inc::Inclusivity)
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`HourEnding(anchor, $(repr(inc)))` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding)
return HourEnding{L,R}(anchor)
end

function HourBeginning(anchor, x::Bool, y::Bool)
L = bound_type(x)
R = bound_type(y)
depwarn("`HourBeginning(anchor, $x, $y)` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning)
return HourBeginning{L,R}(anchor)
end

function HourBeginning(anchor, inc::Inclusivity)
L = bound_type(first(inc))
R = bound_type(last(inc))
depwarn("`HourBeginning(anchor, $(repr(inc)))` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning)
return HourBeginning{L,R}(anchor)
end

function HE(anchor, x::Bool, y::Bool)
L = bound_type(x)
R = bound_type(y)
if !x && y
depwarn("`HE(anchor, $x, $y)` is deprecated, use `HE(anchor)` instead.", :HE)
else
depwarn("`HE(anchor, $x, $y)` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(ceil(anchor, Hour))` instead.", :HE)
end
return HourEnding{L,R}(ceil(anchor, Hour))
end

function HE(anchor, inc::Inclusivity)
L = bound_type(first(inc))
R = bound_type(last(inc))
if !first(inc) && last(inc)
depwarn("`HE(anchor, $(repr(inc)))` is deprecated, use `HE(anchor)` instead.", :HE)
else
depwarn("`HE(anchor, $(repr(inc)))` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(ceil(anchor, Hour))` instead.", :HE)
end
return HourEnding{L,R}(ceil(anchor, Hour))
end

function HB(anchor, x::Bool, y::Bool)
L = bound_type(x)
R = bound_type(y)
if x && !y
depwarn("`HB(anchor, $x, $y)` is deprecated, use `HB(anchor)` instead.", :HB)
else
depwarn("`HB(anchor, $x, $y)` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(floor(anchor, Hour))` instead.", :HB)
end
return HourBeginning{L,R}(floor(anchor, Hour))
end

function HB(anchor, inc::Inclusivity)
L = bound_type(first(inc))
R = bound_type(last(inc))
if first(inc) && !last(inc)
depwarn("`HB(anchor, $(repr(inc)))` is deprecated, use `HB(anchor)` instead.", :HB)
else
depwarn("`HB(anchor, $(repr(inc)))` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(floor(anchor, Hour))` instead.", :HB)
end
return HourBeginning{L,R}(floor(anchor, Hour))
end

@deprecate union(intervals::AbstractVector{<:AbstractInterval}) convert(Vector, union(IntervalSet(intervals)))
@deprecate union!(intervals::AbstractVector{<:AbstractInterval}) convert(Vector, union!(IntervalSet(intervals)))
@deprecate superset(intervals::AbstractVector{<:AbstractInterval}) superset(IntervalSet(intervals))

# END Intervals 1.X.Y deprecations
# END Intervals 2.X.Y deprecations
85 changes: 0 additions & 85 deletions src/inclusivity.jl

This file was deleted.

23 changes: 0 additions & 23 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
# Non-period AnchoredIntervals
@test AnchoredInterval{-10}(10) isa AnchoredInterval
@test AnchoredInterval{25}('a') isa AnchoredInterval

# Deprecated
@test_deprecated AnchoredInterval{Hour(-1),DateTime,Open,Closed}(dt, Inclusivity(false, true))
@test_throws ArgumentError AnchoredInterval{Hour(-1),DateTime,Open,Closed}(dt, Inclusivity(true, true))

@test_deprecated AnchoredInterval{-1,Float64,Open,Closed}(0, Inclusivity(false, true))
@test_throws ArgumentError AnchoredInterval{-1,Float64,Open,Closed}(0, Inclusivity(true, true))
@test_throws MethodError AnchoredInterval{-1,Float64,Open,Closed}(nothing, Inclusivity(false, true))
end

@testset "zero-span" begin
Expand Down Expand Up @@ -774,21 +766,6 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded
@test timezone(aiutc) == tz"UTC"
end

@testset "legacy deserialization" begin
# Serialized string generated on Intervals@1.2 with:
# `julia --project -E 'using Serialization, Intervals; sprint(serialize, AnchoredInterval{-1,Int}(2, true, false))'`.
buffer = IOBuffer(
SERIALIZED_HEADER *
"\x004\x10\x01\x10AnchoredInterval\x1f\v՞\x84\xec\xf7-`\x87\xbb" *
"S\xe1Á\x88A\xd8\x01\tIntervalsD\x02\0\0\x001\xff\xff\xff\xff\0\b\xe14\x10" *
"\x01\vInclusivity\x1f\v՞\x84\xec\xf7-`\x87\xbbS\xe1Á\x88A\xd8,\x02\0DML"
)

interval = deserialize(buffer)
@test interval isa AnchoredInterval
@test interval == AnchoredInterval{-1,Int,Closed,Open}(2)
end

Comment on lines -777 to -791
Copy link
Collaborator

@omus omus May 25, 2023

Choose a reason for hiding this comment

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

You removed the legacy deserialization tests but didn't remove the code from compat.jl which is what this tests. I think the reason you removed this is that the removal of Inclusivity broke the code in compat.jl but we can make a minor change to continue supporting deserialization of the old Interval 1.2 types. It's definitely not necessary with a breaking version change but it's not hard to support:

# These `deserialize` methods are used to be able to deserialize intervals using the
# structure that was used before Intervals 1.3.

abstract type Inclusivity end

function Serialization.deserialize(s::AbstractSerializer, ::Type{Inclusivity})
    L = bound_type(deserialize(s))
    R = bound_type(deserialize(s))
    return L, R
end

function Serialization.deserialize(s::AbstractSerializer, ::Type{Interval{T}}) where T
    left = deserialize(s)
    right = deserialize(s)
    L, R = deserialize(s)  # Deserialize `Inclusivity`

    return Interval{T,L,R}(left, right)
end

function Serialization.deserialize(s::AbstractSerializer, ::Type{AnchoredInterval{P,T}}) where {P,T}
    anchor = deserialize(s)
    L, R = deserialize(s)  # Deserialize `Inclusivity`

    return AnchoredInterval{P,T,L,R}(anchor)
end

With this updated compat.jl code these tests should pass.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is already going into the break v2-DEV release I'm inclined to just drop the compat.jl code. Also, deserialization will likely break again with #217 anyway. If we don't drop it for v2 are we just going to retain this compat code indefinitely?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree we can't keep the serialization compat code forever but it is nice to have some compatibility with old serialized versions. I think having backwards compatible serialization with the latest previous version would be a good goal to have (1.9.0) in this case.

I'd personally probably include this compat change in this PR and then just remove it in #217 just to keep in the commit history.

@testset "floor" begin
# only :anchor, :left, and :right are supported
@test_throws ArgumentError floor(AnchoredInterval{-0.5}(1.0); on=:nothing)
Expand Down
Loading