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): """ 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