Skip to content

Simplify per-chunk interp1d dask path#1

Closed
thodson-usgs wants to merge 2 commits into
fix/interp-map-overlapfrom
simplify/interp-map-overlap
Closed

Simplify per-chunk interp1d dask path#1
thodson-usgs wants to merge 2 commits into
fix/interp-map-overlapfrom
simplify/interp-map-overlap

Conversation

@thodson-usgs

Copy link
Copy Markdown
Owner

Side-by-side comparison PR (not for merging upstream). Shows the one-commit simplification of _interp1d_dask_chunked on top of the current PR branch.

Summary

  • Consolidate call-site guards (is_chunked_array, ndim, dim in var.dims) into one eligibility check at the top of the helper; drops a four-level nested conditional at the call site.
  • Drop cast calls and the cast import — unneeded for the type checker here.
  • Use np.flatnonzero, chained .clip(), np.diff for monotonicity, and [slice(None)] * ndim slicer — more pythonic than the longhand equivalents.
  • Remove the "no blocks" defensive fallback (unreachable once new_np.size > 0 and chunk assignments are clipped).
  • Remove the unused axis=axis default-bind from the per-chunk kernel.
  • Trim comments/docstrings to the why, not the what.
  • Drop restated docstrings and one-use locals in the new tests.

No behavior change.

Test plan

  • pytest xarray/tests/test_interp.py -n auto → 224 passed, 24 skipped, 1 xfailed
  • pre-commit run on touched files passes

[This is Claude Code on behalf of Tim Hodson]

thodson-usgs and others added 2 commits April 23, 2026 18:29
Routes ``xarray.interp(method="linear"|"nearest"|"slinear")`` on a
dask-chunked core dim through a per-chunk dispatch instead of
``apply_ufunc(..., allow_rechunk=True)``. For each target point, look up
the source chunk that contains its coord value and run the interpolator
over that chunk plus a size-1 halo. Per-task memory scales with
``source_chunk + halo`` rather than the full interp axis.

Fall-back path preserves the existing behavior for cubic, multi-dim
interpn, non-monotonic source coord, empty target, and numpy input.

Verified against the existing apply_ufunc path on 200x400 -> 50x100 for
several source-chunk layouts (bit-identical), on a 3D time-chunked input
(time chunking preserved), and on the memory-constrained 6000x5000 case
where the new path beats ``apply_ufunc`` by ~10x.

The per-chunk path materializes 1D source coords (searchsorted-based
routing); data stays lazy. ``test_dataset_interp_datetime_dask`` bumped
its ``raise_if_dask_computes`` budget to account for this.

Related: :issue:`9907` (already closed; same root cause) and
:issue:`10130` (open; partial overlap — single-chunk-source cases still
use the existing path, better addressed by the dask-side guard in
dask/dask#12360).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reduce cognitive load in `_interp1d_dask_chunked` and its call site:

- Consolidate call-site guards (is_chunked_array, ndim, dim-in-dims) into
  one eligibility check at the top of the helper, dropping a four-level
  nested conditional.
- Drop `cast` calls and the `cast` import — unnecessary for the type
  checker here.
- Use `np.flatnonzero`, chained `.clip()`, `np.diff` for monotonicity,
  and `[slice(None)] * ndim` slicer — more pythonic than the
  longhand equivalents.
- Remove the "no blocks" defensive fallback (unreachable once
  `new_np.size > 0` and chunk assignments are clipped).
- Remove the unused `axis=axis` default-bind from the per-chunk kernel.
- Trim comments/docstrings to the why, not the what.
- Drop restated docstrings and one-use locals in the new tests.

No behavior change; test_interp.py suite passes unchanged.

Co-authored-by: Claude <noreply@anthropic.com>
@thodson-usgs thodson-usgs force-pushed the simplify/interp-map-overlap branch from 729b5b9 to 9f4f458 Compare April 24, 2026 01:00
@thodson-usgs thodson-usgs force-pushed the fix/interp-map-overlap branch from 08ab770 to beb87cf Compare April 24, 2026 01:13
@thodson-usgs

Copy link
Copy Markdown
Owner Author

Simplification squashed into PR pydata#11312 on pydata/xarray. [This is Claude Code on behalf of Tim Hodson]

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