Skip to content

fix(features): fillnan='nearest' leaves points with a NaN coordinate NaN - #424

Merged
lachlangrose merged 1 commit into
masterfrom
fix/fillnan-nearest-nan-points
Nov 26, 2026
Merged

lachlangrose merged 1 commit into
masterfrom
fix/fillnan-nearest-nan-points

Conversation

@lachlangrose

Copy link
Copy Markdown
Member

Problem

Since #413 a point with a NaN coordinate evaluates to NaN. GeologicalFeature.evaluate_value(..., fillnan='nearest') then passes those points to cKDTree.query, which raises ValueError: 'x' must be finite, check for nan or inf values.

After #421 the fault-side check of evaluate_gradient uses this path, so evaluate_model_gradient fails on a model with cutting faults (found while merging master into the spec 003 branch, #391: the cutting_faults golden model fails on master a942177b).

Fix

Only points with finite coordinates get the nearest value. A point with a NaN coordinate has no nearest point, so it stays NaN (consistent with #413). A call with no known value also stays NaN instead of failing on an empty tree.

Tests

  • test_fillnan_nearest_keeps_nan_for_points_with_a_nan_coordinate and test_fillnan_nearest_without_known_values_gives_nan fail before the fix and pass after it.
  • Full pytest tests: 2911 passed, 31 skipped.
  • The cutting_faults model gradient of the spec 003 golden models evaluates again (158 points, no NaN rows).

🤖 Generated with Claude Code

https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx

Since #413 a point with a NaN coordinate gives NaN. evaluate_value with
fillnan='nearest' then sent those points to the KD-tree query, which
raised "'x' must be finite". After #421 the fault-side check of a
gradient reaches this path, so evaluate_model_gradient of a model with
cutting faults failed.

Only points with finite coordinates get the nearest value; a point with
a NaN coordinate has no nearest point and stays NaN. A call with no
known value also stays NaN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…ormance

#421 changes the gradient near faults: only the tetrahedra that cross a
fault are made smaller (at most 10 times), and a point whose tetrahedron
still crosses a fault has a NaN gradient. The conflict is in the
refinement loop of GeologicalFeature.evaluate_gradient: take the loop
of master and keep its fault-side check inside probe_points().

On the 21 golden models the branch gives the same bits as master
a942177 for all 97 outputs that master can compute. The other 2
(cutting_faults gradients) fail on master too; #424 fixes that. The
golden references and the batch-count tests are updated in the next
commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
#424 (open against master) stops fillnan='nearest' from sending points
with a NaN coordinate to the KD-tree, which made cutting_faults gradients
fail after #421. It is the same commit as on the PR branch, so the later
master merge has no conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…changed (C-021)

Master #421 changes fault gradients near faults, fault_pitch and fold
rotation angles. 60 outputs of 17 golden models change (mostly
gradients; cutting_faults also some values, restored points and one
model id). The new references come from master a942177 with the fix of
#424, captured at the stored reference points. Evidence:

- the spec 003 branch gives the same bits as that code for all 970
  arrays of the 21 golden models;
- in each updated model, every array that #421 does not change is
  bit-identical to the old reference.

The manifest records the code, the reason and the changed keys under
provenance.reference_updates, with the new sha256 and summaries.

The gradient batch tests replay the refinement of #421: only the
tetrahedra that cross a fault are made smaller, at most 10 times, and a
point whose tetrahedron still crosses a fault is NaN. cutting_faults
group_0 now has 29 distinct (fault, batch) calls (25 before #421; the
refinement probes the crossing subset at each step) and still no
duplicate. A gradient has one scope slot for each probe size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…baseline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
@lachlangrose
lachlangrose merged commit 315dff4 into master Nov 26, 2026
37 checks passed
@lachlangrose
lachlangrose deleted the fix/fillnan-nearest-nan-points branch November 26, 2026 04:48
lachlangrose added a commit that referenced this pull request Nov 26, 2026
The candidate 6c2bbb0 against the Linux baseline (master a942177 with
#424, branch bench/003-linux-baseline at 7b4d910), standard suite twice
each, tracemalloc memory meter. acceptance.json passes: SC-002 0.098,
SC-003 0.122, SC-004 1.09, SC-005 0.216, SC-006 worst 1.215 within the
16 MiB allowance, SC-007 1.06, SC-008 331 s, SC-009 0.365. The
10-million-point check peaks at 7.10 GB with one restored batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
lachlangrose added a commit that referenced this pull request Nov 26, 2026
…fter #425 (C-021)

#425 moves a point on a cutting fault with the frame direction instead of
to NaN. The C-021 capture (master a942177 with #424) had those NaN
points in cutting_faults: 1 restored point, 1 value and 2 gradient rows,
and one model id that they changed. The 5 changed outputs come from
master 315dff4 with #425; the spec branch gives the same bits for all
970 golden arrays. The manifest records the update.

On this branch a frame without faults takes the shared grid lookup, which
does not call evaluate_gradient, so the #425 test of the NaN rule turns
the lookup off to reach the member calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XADRvHhG72666JkYNHtzUx
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