Skip to content

Commit

Permalink
allow Contains on Points (#540)
Browse files Browse the repository at this point in the history
* allow Contains on Points

* no error on Contains for Points
  • Loading branch information
rafaqz authored Sep 26, 2023
1 parent b4decde commit 1df7d85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/LookupArrays/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,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
14 changes: 5 additions & 9 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 Expand Up @@ -1345,11 +1346,6 @@ end
@test selectindices(dims_, ()) == ()
end

@testset "errors" begin
@test_throws ArgumentError DimensionalData.selectindices(X(Sampled(1:4, sampling=Points())), Contains(1))
end


@testset "hasselection" begin
@test hasselection(A, X(At(20)))
@test hasselection(dims(A, X), X(At(20)))
Expand Down

0 comments on commit 1df7d85

Please sign in to comment.