From 233416e44058da0990831be75f3858421c24944a Mon Sep 17 00:00:00 2001 From: David Hassell Date: Mon, 19 Feb 2024 16:04:51 +0000 Subject: [PATCH] dev --- Changelog.rst | 3 +++ cf/field.py | 4 +++- cf/test/test_Field.py | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Changelog.rst b/Changelog.rst index 918ba2a6d2..e8678dc686 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -15,6 +15,9 @@ version 3.17.0 * Fix bug that caused `cf.Field.del_file_location` to fail when updating its metdata constructs (https://github.com/NCAS-CMS/cf-python/issues/707) +* Fix bug that caused incorrect data arrays in some cyclic subspaces + created by `cf.Field.subspace` and `cf.Field.__getitem__` + (https://github.com/NCAS-CMS/cf-python/issues/713) version 3.16.0 -------------- diff --git a/cf/field.py b/cf/field.py index 19e40b2535..a87ea84afb 100644 --- a/cf/field.py +++ b/cf/field.py @@ -405,10 +405,12 @@ def __getitem__(self, indices): f"{self.constructs.domain_axis_identity(_)!r} axis" ) - new = new.roll(shift=shift, axis=iaxis) + new = new.roll(axis=iaxis, shift=shift) else: new = self.copy() + data = new.data + # ------------------------------------------------------------ # Subspace the field construct's data # ------------------------------------------------------------ diff --git a/cf/test/test_Field.py b/cf/test/test_Field.py index b253484d72..449fd32980 100644 --- a/cf/test/test_Field.py +++ b/cf/test/test_Field.py @@ -656,6 +656,13 @@ def test_Field__getitem__(self): with self.assertRaises(IndexError): f[..., [False] * f.shape[-1]] + # Test with cyclic subspace + f.cyclic("grid_longitude") + g = f[:, -3:-5:1] + self.assertEqual(g.shape, (10, 7)) + self.assertTrue(np.allclose(f[:, -3:].array, g[:, :3].array)) + self.assertTrue(f[:, :4].equals(g[:, 3:])) + def test_Field__setitem__(self): f = self.f.copy().squeeze()