From 93ad378d2fa2f505264d479a5c05315a58fce2e9 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 4 Nov 2024 00:57:18 +0100 Subject: [PATCH] check AbstractVector{Int} index sorted order --- src/Lookups/indexing.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Lookups/indexing.jl b/src/Lookups/indexing.jl index d17652e8d..05b691126 100644 --- a/src/Lookups/indexing.jl +++ b/src/Lookups/indexing.jl @@ -8,7 +8,10 @@ for f in (:getindex, :view, :dotview) @propagate_inbounds Base.$f(l::Lookup, i::Union{AbstractVector,Colon}) = rebuild(l; data=Base.$f(parent(l), i)) @propagate_inbounds function Base.$f(l::Union{Sampled,Categorical}, i::AbstractVector{Int}) - rebuild(l; data=Base.$f(parent(l), i), order=Unordered()) + if isordered(l) + issorted(i) || throw(ArgumentError("For `ForwardOrdered` or `ReverseOrdered` lookups, indices of `AbstractVector{Int}` must be in ascending order")) + end + rebuild(l; data=Base.$f(parent(l), i)) end # Selector gets processed with `selectindices` @propagate_inbounds Base.$f(l::Lookup, i::SelectorOrInterval) = Base.$f(l, selectindices(l, i))