Skip to content

Name kriging singular-fallback variance '{name}_variance'#3289

Merged
brendancol merged 2 commits into
mainfrom
deep-sweep-api-consistency-interpolate-2026-06-12-01
Jun 12, 2026
Merged

Name kriging singular-fallback variance '{name}_variance'#3289
brendancol merged 2 commits into
mainfrom
deep-sweep-api-consistency-interpolate-2026-06-12-01

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Closes #3285

  • kriging(..., return_variance=True) has a fallback for the case where the kriging matrix stays singular after regularisation: it returns NaN rasters via prediction, prediction.copy(). The copy kept the prediction's name, so both arrays came back named '{name}' while the normal path names the variance '{name}_variance'. Anything keying on .name (xr.merge, building a Dataset from the pair) collapsed the two into one variable.
  • The fallback now renames the copy to f'{name}_variance', matching the normal path.
  • Also pins the names on the normal path in the existing test_return_variance.

Backend coverage: the fallback runs before backend dispatch, so one code path covers numpy, cupy, dask+numpy, and dask+cupy. Variance names on the normal path were verified on numpy and cupy.

Test plan:

  • New test_return_variance_name_on_singular_fallback forces the singular path via monkeypatch and checks both names plus NaN contents
  • pytest xrspatial/tests/test_interpolation.py -- 67 passed

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Jun 12, 2026

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Name kriging singular-fallback variance '{name}_variance'

Blockers (must fix before merge)

  • .claude/sweep-api-consistency-state.csv: the rewrite flipped every line ending from LF to CRLF (csv.DictWriter defaults to \r\n when the file is opened with newline=''). The diff touches all 13 rows instead of adding one, and since the state file merges as plain text (#2754), this will whole-file-conflict with every other sweep branch that commits a row. Rewrite with lineterminator='\n' so the diff is just the new interpolate row.

Suggestions (should fix, not blocking)

  • none

Nits (optional improvements)

  • none

What looks good

  • The fix is the minimal correct change: _kriging.py:499 now renames the copied DataArray to f'{name}_variance', matching the normal path at line 527.
  • test_return_variance_name_on_singular_fallback forces the singular path by monkeypatching _build_kriging_matrix (which kriging() resolves as a module global, so the patch takes effect) and checks both names plus the NaN contents.
  • The existing test_return_variance now pins the default names on the normal path, so a regression in either path gets caught.

Checklist

  • Algorithm matches reference/paper (naming-only change, no numerics touched)
  • All implemented backends produce consistent results (fallback runs before backend dispatch)
  • NaN handling is correct (fallback still returns all-NaN rasters; test asserts it)
  • Edge cases are covered by tests (singular path was previously untested)
  • Dask chunk boundaries handled correctly (n/a)
  • No premature materialization or unnecessary copies
  • Benchmark exists or is not needed (n/a for a name fix)
  • README feature matrix updated (n/a)
  • Docstrings present and accurate (kriging docstring already describes the tuple return)
  • State CSV line endings (see blocker)

@brendancol brendancol force-pushed the deep-sweep-api-consistency-interpolate-2026-06-12-01 branch from e3fd965 to 03b31d2 Compare June 12, 2026 16:45

@brendancol brendancol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review after blocker fix

The CSV blocker from the first review is resolved: the state file is now main's bytes plus a single inserted interpolate row (1 insertion, 0 deletions against main), so other rows keep their existing line endings (two rows on main end with CRLF; they are untouched). No whole-file conflict risk for sibling sweep branches.

The code and test changes are unchanged from the first review and still look correct. pytest xrspatial/tests/test_interpolation.py passes (67) after the rebase.

No remaining findings.

@brendancol brendancol merged commit 299f4a2 into main Jun 12, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kriging() singular-matrix fallback returns variance DataArray without the _variance name suffix

1 participant