Skip to content

Order NaN, missing, and -0.0 like Base in ChainedVector findmin and extrema - #134

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-findmin-extrema-order
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-findmin-extrema-order

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

A ChainedVector should give the same answers as the same data in a Vector. findmin, argmin, and extrema did not when the data has NaN, missing, or -0.0. Base treats NaN and missing as the minimum for findmin and propagates them through extrema. The ChainedVector methods compared values with isless and < instead, so they skipped NaN, threw on missing, and lost the sign of -0.0:

julia> findmin(ChainedVector([[1.0], [NaN, 0.5]]))
(0.5, 3)          # Vector gives (NaN, 2)

julia> extrema(ChainedVector([[1.0], [NaN, 0.5]]))
(1.0, 1.0)        # Vector gives (NaN, NaN)

julia> extrema(ChainedVector([[0.0], [-0.0]]))
(0.0, 0.0)        # Vector gives (-0.0, 0.0)

julia> extrema(ChainedVector([[1], [missing, 0]]))
ERROR: TypeError: non-boolean (Missing) used in boolean context

What changed

  • findmax and findmin call Base's findmax/findmin on each chunk, then on the chunk winners, so Base decides every comparison, including ties.
  • extrema combines the chunk results with Base's minimum and maximum.
  • Raise the Julia floor to 1.10, the current LTS and CSV.jl's floor. Base's findmax(f, A) and findmin(f, A), which do the per-chunk work, need Julia 1.7.

Scope

  • Values without NaN, missing, or -0.0 give the same results as before.
  • Empty chunks left by resize!, append!, and prepend! are a separate fix.

Blast radius

Callers that hit NaN, missing, or -0.0 now get Base's answer. The next release must be a minor version (1.5.0), because General's AutoMerge allows narrowing the julia compat range only in a non-patch release. Users on Julia 1.3 to 1.9 stay on SentinelArrays 1.4.x.

Verification

  • The new test fails on main and passes on this branch (Julia 1.12.6).
  • The full test suite passes locally on Julia 1.12.6 and 1.10.11, on this branch alone and with all twelve fix PRs (Keep ChainedVector folds in order and reduce empty vectors like Vector #133 to Reverse SentinelVectors with missing values and an undef sentinel #144) merged together.
  • The new test compares against Vector at every split point of six inputs with ties, several NaNs, missing, and both zero signs.
  • The seeded differential harness from the sweep (179 operations on ChainedVector, SentinelVector, and MissingVector, compared with Vector) reports this mismatch on main and not with the fixes applied.
  • Timing (10M Float64 values in 8 chunks, Julia 1.12.6, Chairmarks minimum of 2 interleaved runs per side on a loaded shared machine): findmax 63 → 12.5 ms and findmin 63 → 13 ms, because Base's findmax on each chunk is faster than the old loop. findmin on Int data 5.4 → 5.6 ms. extrema stays at 43 ms.

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 23:04
Fails on main; passes with the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xtrema

findmin compared chunk values with isless, so NaN and missing never
won, and extrema combined chunks with < and >, which skips NaN, throws
on missing, and drops the sign of -0.0. Use Base's findmax/findmin on
each chunk and then on the chunk winners, and combine extrema with
minimum and maximum. findmax(f, A) needs Julia 1.7, so raise the floor
to 1.10, which General's AutoMerge already requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant