Skip to content

Correctness issues and errors after sorting #110

@tecosaur

Description

@tecosaur

Hello,

I was recently surprised to find that when sorting a column I read from a CSV ...the numbers changed?

Using Julia 1.11 and the latest releases of SentinelArrays, CSV, and DataFrames, I executed:

CSV.read("my.csv", DataFrame).column |> unique! |> sort

This produced some really surprising values, and turned up some incredibly buggy behavior:

julia> cv = ChainedVector([rand(1:100, 20) for _ in 1:10])
[...]

julia> unique!(cv)
[...]

julia> sum(cv)
5073

julia> sum(sort(cv))
2236548265497175

If I keep on running sum(sort(cv)) the result bounces around a bit, it seems like there's something stochastic happening?

julia> sum(sort(cv))
4399

julia> sum(sort(cv))
4378

julia> sum(sort(cv))
4400

This can also produce an error instead of an incorrect result sometimes.

julia> sum(cv)
4414

julia> sum(sort(cv))
ERROR: ArgumentError: out of range arguments to copyto! on ChainedVector
Stacktrace:
 [1] copyto!(dest::ChainedVector{…}, doffs::Int64, src::ChainedVector{…}, soffs::Int64, n::Int64)
   @ SentinelArrays ~/.julia/packages/SentinelArrays/ob2QK/src/chainedvector.jl:475
 [2] copyto!
   @ ~/.julia/packages/SentinelArrays/ob2QK/src/chainedvector.jl:465 [inlined]
 [3] copymutable
   @ ./abstractarray.jl:1192 [inlined]
 [4] sort(v::ChainedVector{Int64, Vector{Int64}})
   @ Base.Sort ./sort.jl:1720
 [5] top-level scope
   @ REPL[39]:1
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions