From bffcdbd0be7c91655acae1388420c59e7389ef6b Mon Sep 17 00:00:00 2001 From: Zackary Loevseth <307867630+HayosoAi@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:28:24 -0700 Subject: [PATCH] DOC: Add a Dataset.reindex_like example Add a concrete example showing label alignment and NaN fill values. Created by Codex on behalf of @HayosoAi. Co-authored-by: Codex --- xarray/core/dataset.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 7976a8b5f62..5895bde0422 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3566,6 +3566,38 @@ def reindex_like( DataArray.reindex_like align + Examples + -------- + Reindex time-series observations to the time index of another dataset. + Values for new index labels are filled with ``NaN`` by default: + + >>> observations = xr.Dataset( + ... {"temperature": ("time", [18.0, 21.0])}, + ... coords={"time": [0, 2]}, + ... ) + >>> observations + Size: 32B + Dimensions: (time: 2) + Coordinates: + * time (time) int64 16B 0 2 + Data variables: + temperature (time) float64 16B 18.0 21.0 + >>> target = xr.Dataset(coords={"time": [0, 1, 2]}) + >>> target + Size: 24B + Dimensions: (time: 3) + Coordinates: + * time (time) int64 24B 0 1 2 + Data variables: + *empty* + >>> observations.reindex_like(target) + Size: 48B + Dimensions: (time: 3) + Coordinates: + * time (time) int64 24B 0 1 2 + Data variables: + temperature (time) float64 24B 18.0 nan 21.0 + """ return alignment.reindex_like( self,