Skip to content

Commit 742adb5

Browse files
cstjeandlfivefifty
authored andcommitted
Support for missing values (#48)
* Support `missing in a..b` * Add tests for missing interval endpoints * Drop 0.6 compatibility * Add test cases
1 parent 72ab3fb commit 742adb5

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.6
87
- 0.7
98
- 1.0
109
- nightly

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 1.0
1+
julia 0.7

src/IntervalSets.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ using Base: @pure
66
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash,
77
union, intersect, minimum, maximum, extrema, range,
88

9-
using Compat.Statistics
10-
import Compat.Statistics: mean
9+
using Statistics
10+
import Statistics: mean
1111

12-
13-
using Compat
14-
using Compat.Dates
12+
using Dates
1513

1614
export AbstractInterval, Interval, OpenInterval, ClosedInterval,
1715
, .., ±, ordered, width, duration, leftendpoint, rightendpoint, endpoints,
@@ -133,6 +131,11 @@ in(v::Complex, I::TypedEndpointsInterval{:open,:open}) = isreal(v) && in(real(v)
133131
in(v::Complex, I::TypedEndpointsInterval{:closed,:open}) = isreal(v) && in(real(v), I)
134132
in(v::Complex, I::TypedEndpointsInterval{:open,:closed}) = isreal(v) && in(real(v), I)
135133

134+
in(::Missing, I::TypedEndpointsInterval{:closed,:closed}) = !isempty(I) && missing
135+
in(::Missing, I::TypedEndpointsInterval{:open,:open}) = !isempty(I) && missing
136+
in(::Missing, I::TypedEndpointsInterval{:closed,:open}) = !isempty(I) && missing
137+
in(::Missing, I::TypedEndpointsInterval{:open,:closed}) = !isempty(I) && missing
138+
136139
in(a::AbstractInterval, b::TypedEndpointsInterval{:closed,:closed}) =
137140
(leftendpoint(a) leftendpoint(b)) & (rightendpoint(a) rightendpoint(b))
138141
in(a::TypedEndpointsInterval{:open,:open}, b::TypedEndpointsInterval{:open,:open}) =

test/runtests.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using IntervalSets
2-
using Compat
3-
using Compat.Test
4-
using Compat.Dates
5-
using Compat.Statistics
6-
import Compat.Statistics: mean
2+
using Test
3+
using Dates
4+
using Statistics
5+
import Statistics: mean
76

87
import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval
98

@@ -593,13 +592,26 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
593592
@test_throws InexactError convert(OpenInterval, I)
594593
end
595594

595+
@testset "Missing endpoints" begin
596+
@test ismissing(2 in 1..missing)
597+
@test_broken ismissing(2 in missing..1) # would be fixed by julialang#31171
598+
end
599+
596600
@testset "issubset" begin
597601
@test issubset(0.1, 0.0..1.0) == true
598602
@test issubset(0.0, 0.0..1.0) == true
599603
@test issubset(1.1, 0.0..1.0) == false
600604
@test issubset(0.0, nextfloat(0.0)..1.0) == false
601605
end
602606

607+
@testset "missing in" begin
608+
@test ismissing(missing in 0..1)
609+
@test !(missing in 1..0)
610+
@test ismissing(missing in OpenInterval(0, 1))
611+
@test ismissing(missing in Interval{:closed, :open}(0, 1))
612+
@test ismissing(missing in Interval{:open, :closed}(0, 1))
613+
end
614+
603615
@testset "complex in" begin
604616
@test 0+im 0..2
605617
@test 0+0im 0..2

0 commit comments

Comments
 (0)