From 7515cbc016f58175b2cde4529cda24af3d796d2f Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Mon, 27 Apr 2026 14:36:39 +0100 Subject: [PATCH 1/2] Remove unnecessary t coord creation in lazy_load This is already handled in apply_geometry --- xbout/lazyload.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/xbout/lazyload.py b/xbout/lazyload.py index aeb59940..e4c53630 100644 --- a/xbout/lazyload.py +++ b/xbout/lazyload.py @@ -360,9 +360,5 @@ def lazy_open_boutdataset( f"Variable '{name}' has only one of x/y dimensions and will be skipped" ) - coords = {} - if "t_array" in ds: - coords["t"] = ds["t_array"].values - # Create a global dataset - return xr.Dataset(data_vars, coords=coords, attrs={"metadata": metadata}) + return xr.Dataset(data_vars, attrs={"metadata": metadata}) From 051d189d52ce446307bbe13ad10a0fdadc200b11 Mon Sep 17 00:00:00 2001 From: Mike Kryjak Date: Mon, 27 Apr 2026 15:04:06 +0100 Subject: [PATCH 2/2] Always drop t_array if present Previously, this would only happen if "t" was in dims but not in coords, which could be legacy BOUT++ behaviour? Keeping two time arrays is asking for trouble. --- xbout/geometries.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xbout/geometries.py b/xbout/geometries.py index 35c541ea..9493fde8 100644 --- a/xbout/geometries.py +++ b/xbout/geometries.py @@ -127,12 +127,15 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None): ycoord = updated_ds.metadata["bout_ydim"] zcoord = updated_ds.metadata["bout_zdim"] - if (tcoord not in updated_ds.coords) and (tcoord in updated_ds.dims): + if "t_array" in updated_ds: + # Always use t_array as the ground truth for the time coordinate + # Create the time coordinate from t_array # Slightly odd looking way to create coordinate ensures 'index variable' is # created, which using set_coords() does not (possible xarray bug? # https://github.com/pydata/xarray/issues/4417 - updated_ds[tcoord] = updated_ds["t_array"] + if tcoord in updated_ds.dims: + updated_ds[tcoord] = updated_ds["t_array"] updated_ds = updated_ds.drop_vars("t_array") if xcoord not in updated_ds.coords: