From 1df7d8522ab12dba6c496c945c3e1c49f35d62db Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 26 Sep 2023 21:15:44 +0200 Subject: [PATCH] allow Contains on Points (#540) * allow Contains on Points * no error on Contains for Points --- src/LookupArrays/selector.jl | 8 ++------ test/selector.jl | 14 +++++--------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/LookupArrays/selector.jl b/src/LookupArrays/selector.jl index a494d411e..81ef07426 100644 --- a/src/LookupArrays/selector.jl +++ b/src/LookupArrays/selector.jl @@ -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()) diff --git a/test/selector.jl b/test/selector.jl index fdd7c01db..c447b5483 100644 --- a/test/selector.jl +++ b/test/selector.jl @@ -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 @@ -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 @@ -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)))