Skip to content

Commit

Permalink
Remove deprecated methods and bump version to v0.7.0 (#107)
Browse files Browse the repository at this point in the history
* remove deprecated functions and methods

* update tests

* bump version to v0.7.0
  • Loading branch information
hyrodium authored May 29, 2022
1 parent 39b9007 commit 42f7855
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "IntervalSets"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.6.2"
version = "0.7.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
50 changes: 1 addition & 49 deletions src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Statistics: mean
using Dates

export AbstractInterval, Interval, OpenInterval, ClosedInterval,
, .., ±, ordered, width, duration, leftendpoint, rightendpoint, endpoints,
, .., ±, ordered, width, leftendpoint, rightendpoint, endpoints,
isopenset, isclosedset, isleftclosed, isrightclosed,
isleftopen, isrightopen, closedendpoints,
infimum, supremum
Expand Down Expand Up @@ -227,55 +227,7 @@ Clamp the scalar `t` such that the result is in the interval `i`.
clamp(t, i::TypedEndpointsInterval{:closed,:closed}) =
clamp(t, leftendpoint(i), rightendpoint(i))


"""
duration(iv)
calculates the the total number of integers or dates of an integer or date
valued interval. For example, `duration(0..1)` is 2, while `width(0..1)` is 1.
"""
function duration(A::TypedEndpointsInterval{:closed,:closed,T}) where {T<:Integer}
# TODO: Remove this method in the next breaking release
Base.depwarn("`duration` will be removed in the next breaking release because it is ill-defined concept. " *
"If you need 3 from 2..4, replace duration(2..4) with width(2..4)+1", :duration)
max(0, Int(A.right - A.left) + 1)
end
function duration(A::TypedEndpointsInterval{:closed,:closed,Date})
# TODO: Remove this method in the next breaking release
Base.depwarn("`duration` will be removed in the next breaking release because it is ill-defined concept. " *
"If you need 961 from A=Date(2018,08,08)..Date(2021,03,25), replace duration(A) with Dates.days(width(A))+1", :duration)
max(0, Dates.days(A.right - A.left) + 1)
end

include("interval.jl")

# convert numbers to intervals
# TODO: These conversions will be removed in the next breaking release (#97)
function convert(::Type{AbstractInterval}, x::Number)
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
x..x
end
function convert(::Type{AbstractInterval{T}}, x::Number) where T
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
convert(AbstractInterval{T}, convert(AbstractInterval, x))
end
function convert(::Type{TypedEndpointsInterval{:closed,:closed}}, x::Number)
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
x..x
end
function convert(::Type{TypedEndpointsInterval{:closed,:closed,T}}, x::Number) where T
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
convert(AbstractInterval{T}, convert(AbstractInterval, x))
end
function convert(::Type{ClosedInterval}, x::Number)
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
x..x
end
function convert(::Type{ClosedInterval{T}}, x::Number) where T
Base.depwarn("`The conversion number to interval will be removed; construct an interval explicitly, e.g., `x..x`.", :convert)
convert(AbstractInterval{T}, convert(AbstractInterval, x))
end

include("findall.jl")

end # module
6 changes: 0 additions & 6 deletions src/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ Construct a ClosedInterval `iv` spanning the region from
`center - halfwidth` to `center + halfwidth`.
"""
±(x, y) = ClosedInterval(x - y, x + y)
function ±(x::CartesianIndex, y)
# TODO: Remove this method in the next breaking release
Base.depwarn("This method for `CartesianIndex(1,2) ± 1 == (0..2, 1..3)` is not consistent and will be removed because CartesianIndex(1,1) + 1 is not defined. " *
"If you need tuple such as `(0..2, 1..3)` from `CartesianIndex`, just write it in a plain tuple form.", :±)
(xy = y * one(x); map(ClosedInterval, (x - xy).I, (x + xy).I))
end
±(x::CartesianIndex, y::CartesianIndex) = ClosedInterval(x-y, x+y)

show(io::IO, I::ClosedInterval) = print(io, leftendpoint(I), "..", rightendpoint(I))
Expand Down
17 changes: 0 additions & 17 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end
M = @inferred(ClosedInterval(2, 5.0))
@test string(M) == "2.0..5.0"
N = @inferred(ClosedInterval(UInt8(255), 300))
O = @inferred(CartesianIndex(1, 2, 3, 4) ± 2)
@test O == (-1..3, 0..4, 1..5, 2..6)

x, y = CartesianIndex(1, 2, 3, 4), CartesianIndex(1, 2, 3, 4)
O = @inferred x±y
Expand Down Expand Up @@ -136,10 +134,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end
@test mean(0..1) == 0.5

@test promote(1..2, 1.0..2.0) === (1.0..2.0, 1.0..2.0)

@test duration(1..2) == 2
# duration deliberately not defined for non-integer intervals
@test_throws MethodError duration(1.2..2.4)
end

@testset "Unitful interval" begin
Expand All @@ -154,8 +148,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end
@test width(ClosedInterval(A, B)) == Dates.Day(59)
@test width(ClosedInterval(B, A)) == Dates.Day(0)
@test isempty(ClosedInterval(B, A))
@test duration(ClosedInterval(A, B)) 60
@test duration(ClosedInterval(B, A)) 0
end

@testset "Convert" begin
Expand Down Expand Up @@ -221,15 +213,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end
@test 1.0..2.0 === 1.0..2 === 1..2.0 === ClosedInterval{Float64}(1..2) ===
Interval(1.0,2.0)

# TODO: Remove this test in the next breaking release (#97)
@test convert(AbstractInterval, 1.0) ==
convert(AbstractInterval{Float64}, 1) ==
convert(TypedEndpointsInterval{:closed,:closed}, 1.0) ==
convert(TypedEndpointsInterval{:closed,:closed,Float64}, 1) ==
convert(ClosedInterval, 1.0) ==
convert(ClosedInterval{Float64}, 1) ==
1.0..1.0

@test promote_type(Interval{:closed,:open,Float64}, Interval{:closed,:open,Int}) ===
Interval{:closed,:open,Float64}
end
Expand Down

2 comments on commit 42f7855

@hyrodium
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/61271

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 42f7855164d1338a7280dcdca79995a40c6e1b10
git push origin v0.7.0

Please sign in to comment.