Skip to content

Commit

Permalink
allow Contains on Points
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Sep 26, 2023
1 parent cd77569 commit 2f0da10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/LookupArrays/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,8 @@ function contains(::NoSampling, l::LookupArray, sel::Contains; kw...)
at(l, At(val(sel)); kw...)
end
# Points --------------------------------------
function contains(::Points, l::LookupArray, sel::Contains; err=_True())
if err isa _True
throw(ArgumentError("Points LookupArray cannot use `Contains`, use `Near` or `At` for Points."))
else
nothing
end
function contains(::Points, l::LookupArray, sel::Contains; kw...)
at(l, At(val(sel)); kw...)
end
# Intervals -----------------------------------
function contains(sampling::Intervals, l::LookupArray, sel::Contains; err=_True())
Expand Down
9 changes: 5 additions & 4 deletions test/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,11 @@ A = DimArray([1 2 3; 4 5 6], dims_)
@test at(rev, At(30)) == 1
end

@testset "contains" begin
@test contains(fwd, Contains(30)) == 26
@test contains(rev, Contains(30)) == 1
end

@testset "near" begin
@test near(fwd, Near(50)) == 26
@test near(fwd, Near(0)) == 1
Expand All @@ -927,10 +932,6 @@ A = DimArray([1 2 3; 4 5 6], dims_)
@test_throws ArgumentError near(Sampled((5.0:30.0); order=Unordered(), sampling=Points()), Near(30.1))
end

@testset "contains" begin
@test_throws ArgumentError contains(fwd, Contains(50))
end

end

end
Expand Down

0 comments on commit 2f0da10

Please sign in to comment.