From d266e3ca7583fdf7a586096ece3be999d605ab73 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 16 Jan 2020 10:56:39 +0000 Subject: [PATCH 1/2] allow derived coordinates to be removed --- lib/iris/cube.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/iris/cube.py b/lib/iris/cube.py index a246b97e1c..be1a44d1d8 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -1270,6 +1270,9 @@ def _remove_coord(self, coord): for coord_, dims in self._aux_coords_and_dims if coord_ is not coord ] + for aux_factory in self.aux_factories: + if coord._as_defn() == aux_factory._as_defn(): + self.remove_aux_factory(aux_factory) def remove_coord(self, coord): """ From b5db944062b5a7490eee520e938bb7331e34542e Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Mon, 8 Jun 2020 15:30:35 +0100 Subject: [PATCH 2/2] add test --- .../results/derived/removed_derived_coord.cml | 119 ++++++++++++++++++ lib/iris/tests/test_hybrid.py | 5 + 2 files changed, 124 insertions(+) create mode 100644 lib/iris/tests/results/derived/removed_derived_coord.cml diff --git a/lib/iris/tests/results/derived/removed_derived_coord.cml b/lib/iris/tests/results/derived/removed_derived_coord.cml new file mode 100644 index 0000000000..12feb2b643 --- /dev/null +++ b/lib/iris/tests/results/derived/removed_derived_coord.cml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/iris/tests/test_hybrid.py b/lib/iris/tests/test_hybrid.py index 28a733f7cc..29bad235c7 100644 --- a/lib/iris/tests/test_hybrid.py +++ b/lib/iris/tests/test_hybrid.py @@ -51,6 +51,11 @@ def test_indexing(self): _ = cube.coord("altitude") self.assertCML(cube, ("derived", "column.cml")) + def test_removing_derived_coord(self): + cube = self.cube + cube.remove_coord("altitude") + self.assertCML(cube, ("derived", "removed_derived_coord.cml")) + def test_removing_sigma(self): # Check the cube remains OK when sigma is removed. cube = self.cube