Skip to content

Commit

Permalink
Fix sorting missing values with offset indices (#48864)
Browse files Browse the repository at this point in the history
* Fix sorting missing values with offset indices

* Add tests
  • Loading branch information
LilithHafner committed Mar 6, 2023
1 parent 0f7b419 commit 7eb9615
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ Base.@propagate_inbounds function Base.setindex!(v::WithoutMissingVector, x, i)
v
end
Base.size(v::WithoutMissingVector) = size(v.data)
Base.axes(v::WithoutMissingVector) = axes(v.data)

"""
send_to_end!(f::Function, v::AbstractVector; [lo, hi])
Expand Down
7 changes: 7 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,13 @@ end
end
end

@testset "Offset with missing (#48862)" begin
v = [-1.0, missing, 1.0, 0.0, missing, -0.5, 0.5, 1.0, -0.5, missing, 0.5, -0.8, 1.5, NaN]
vo = OffsetArray(v, (firstindex(v):lastindex(v)).+100)
@test issorted(sort!(vo))
@test issorted(v)
end

@testset "searchsortedfirst/last with generalized indexing" begin
o = OffsetVector(1:3, -2)
@test searchsortedfirst(o, 4) == lastindex(o) + 1
Expand Down

0 comments on commit 7eb9615

Please sign in to comment.