From 45acde614dd4d76ce821c767aa306c93abb85b7b Mon Sep 17 00:00:00 2001 From: David Bold Date: Tue, 17 Feb 2026 12:30:54 +0100 Subject: [PATCH 1/2] Use assign_coords Do not modify attributes in-place --- xbout/tests/test_boutdataset.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xbout/tests/test_boutdataset.py b/xbout/tests/test_boutdataset.py index a03c4ed9..300ed9d9 100644 --- a/xbout/tests/test_boutdataset.py +++ b/xbout/tests/test_boutdataset.py @@ -1195,10 +1195,11 @@ def test_integrate_midpoints_slab(self, bout_xyt_example_files): x = np.linspace(0.05, 9.95, 100)[np.newaxis, :, np.newaxis, np.newaxis] y = np.linspace(0.1, 21.9, 110)[np.newaxis, np.newaxis, :, np.newaxis] z = np.linspace(0.15, 35.85, 120)[np.newaxis, np.newaxis, np.newaxis, :] - ds["t"].data[...] = t.squeeze() - ds["dx"].data[...] = 0.1 - ds["dy"].data[...] = 0.2 - ds["dz"] = 0.3 + dx = ds["dx"].copy() + dx.data[...] = 0.1 + dy = ds["dy"].copy() + dy.data[...] = 0.2 + ds.assign_coords(t=t.squeeze(), dx=dx, dy=dy, dz=0.3) tfunc = 1.5 * t xfunc = x**2 yfunc = 10.0 * y - y**2 From fc28b5b769d91cd1cd22bfbc9cc53f6ea58e815b Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 18 Feb 2026 11:43:19 +0100 Subject: [PATCH 2/2] assign_coords does return the updated dataset --- xbout/tests/test_boutdataset.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xbout/tests/test_boutdataset.py b/xbout/tests/test_boutdataset.py index 300ed9d9..61c03d11 100644 --- a/xbout/tests/test_boutdataset.py +++ b/xbout/tests/test_boutdataset.py @@ -1195,11 +1195,14 @@ def test_integrate_midpoints_slab(self, bout_xyt_example_files): x = np.linspace(0.05, 9.95, 100)[np.newaxis, :, np.newaxis, np.newaxis] y = np.linspace(0.1, 21.9, 110)[np.newaxis, np.newaxis, :, np.newaxis] z = np.linspace(0.15, 35.85, 120)[np.newaxis, np.newaxis, np.newaxis, :] - dx = ds["dx"].copy() - dx.data[...] = 0.1 - dy = ds["dy"].copy() - dy.data[...] = 0.2 - ds.assign_coords(t=t.squeeze(), dx=dx, dy=dy, dz=0.3) + ds["dx"][...] = 0.1 + ds["dy"][...] = 0.2 + ds = ds.assign_coords( + t=t.squeeze(), + dx=ds.dx, + dy=ds.dy, + dz=0.3, + ) tfunc = 1.5 * t xfunc = x**2 yfunc = 10.0 * y - y**2