Skip to content

Commit

Permalink
selectors should error with NaN (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz authored Nov 2, 2024
1 parent e433038 commit 55c765c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Lookups/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ function near(lookup::Lookup, sel::Near; kw...)
if !isregular(lookup) && !iscenter(lookup)
throw(ArgumentError("Near is not implemented for Irregular or Explicit with Start or End locus. Use Contains"))
end
val(sel) isa AbstractFloat && isnan(val(sel)) && throw(ArgumentError("NaN not allowed in `Near`"))
return near(order(lookup), sampling(lookup), lookup, sel; kw...)
end
near(order::Order, ::NoSampling, lookup::Lookup, sel::Near; kw...) = at(lookup, At(val(sel)); kw...)
Expand Down Expand Up @@ -417,7 +418,10 @@ function contains(l::NoLookup, sel::Contains; err=_True(), kw...)
throw(SelectorError(l, val(sel)))
end
end
contains(l::Lookup, sel::Contains; kw...) = contains(sampling(l), l, sel; kw...)
function contains(l::Lookup, sel::Contains; kw...)
val(sel) isa AbstractFloat && isnan(val(sel)) && throw(ArgumentError("NaN not allowed in `Contains`"))
contains(sampling(l), l, sel; kw...)
end
# NoSampling (e.g. Categorical) just uses `at`
function contains(::NoSampling, l::Lookup, sel::Contains; kw...)
at(l, At(val(sel)); kw...)
Expand Down Expand Up @@ -632,7 +636,11 @@ end
# cycled_sel = rebuild(sel; val=)
# near(no_cycling(lookup), cycled_sel; kw...)
# end
between(l::Lookup, interval::Interval) = between(sampling(l), l, interval)
function between(l::Lookup, interval::Interval)
interval.left isa AbstractFloat && (isnan(interval.left) || isnan(interval.right)) &&
throw(ArgumentError("NaN not allowed in selectors"))
between(sampling(l), l, interval)
end
# This is the main method called above
function between(sampling::Sampling, l::Lookup, interval::Interval)
isordered(l) || throw(ArgumentError("Cannot use an interval or `Between` with `Unordered`"))
Expand Down

0 comments on commit 55c765c

Please sign in to comment.