﻿# Xarray interpolation sorting is an explicit coordinate contract

Xarray interpolation sorting is an explicit coordinate contract. A focused scientific-computing guide with the documented mechanism, a reproducible validation scenario, evidence and operational limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/science-xarray-interp-assume-sorted/
Language: en

Xarray interpolation has an explicit assumption about coordinate ordering. With assume_sorted disabled, the documented path can sort coordinates before interpolation; enabling it instead asserts the required ordering. A scientific AI loader should not toggle that flag as a generic speed switch without validating the coordinate contract and preserving the pairing between coordinates and values.

## The scientific interface

The DataArray.interp documentation permits arbitrary source order when assume_sorted=False and describes sorting first. The true setting requires monotonically increasing coordinates. That promise is separate from uniqueness, support for a chosen interpolation method and the treatment of out-of-range target positions. Sorting is not a general deduplication or data-quality repair. A loader must also retain matching source values rather than sorting a detached coordinate vector and leaving the associated measurements in their original order.

## Implementation details

Validate ordering before selecting the asserted-sorted path and record the source grid with its identity-bearing values. Keep target coordinates, interpolation method and any extrapolation options as separate configuration. Treat duplicate or otherwise unsupported source coordinates with an explicit policy rather than assuming sorting resolves them. Compare prepared values at known positions before measuring interpolation throughput. If a regular target grid is created for a sequence model, preserve the original irregular observations as provenance and distinguish interpolated samples from newly measured physical evidence.

## A constructed validation case

Create a known function sampled on a deliberately shuffled coordinate grid. Compare the documented sorting path with a correctly sorted paired-input path, then add an incorrectly asserted sorted case as a negative control. Include repeated coordinates and outside-range targets under separately declared expectations. Acceptance requires truthful ordering assumptions and value-coordinate association, not a universal guarantee that every method handles every source-grid defect. Keep exact source and target coordinates so later backend changes can be checked against the same interpolation problem.

## Numerical and data limits

Correct interpolation setup does not establish adequate spatial or temporal resolution for a physical process. Sampling, noise and model error need separate assessment. Keep coordinate preparation explicit so a sorting flag cannot silently redefine the scientific function used as an AI input or reference.

## Primary references

[Xarray DataArray.interp API](https://docs.xarray.dev/en/stable/generated/xarray.DataArray.interp.html); [Xarray interpolation guide](https://docs.xarray.dev/en/stable/user-guide/interpolation.html).

This is a proposed scientific-interface validation, not an executed Retrivium benchmark. Preserve the implementation version and unresolved outcomes; interface documentation does not establish the accuracy or performance of a scientific model.

## Related reading

[Tensor axes in a language model: batch, sequence and hidden width](/journal/tensor-axes-batch-sequence-hidden/); [Validate safetensors weight artifacts separately from repository code](/journal/safetensors-artifact-validation/).
