From 2465c355466402a3a970c14a91f654efeaa56e82 Mon Sep 17 00:00:00 2001 From: Yang Yunyi Date: Sat, 10 Apr 2021 01:24:56 +0800 Subject: [PATCH 1/5] Add a method to return a CubeList from CubeList.copy() --- lib/iris/cube.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/iris/cube.py b/lib/iris/cube.py index a15951900b..90b233ff5a 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -707,6 +707,13 @@ def realise_data(self): """ _lazy.co_realise_cubes(*self) + def copy(self): + """ + Return a CubeList when CubeList.copy() is called. + """ + if type(self) == CubeList: + return deepcopy(self) + def _is_single_item(testee): """ From 12359f056313763e867cf679a7a24c905ab0ca85 Mon Sep 17 00:00:00 2001 From: Yang Yunyi Date: Thu, 27 May 2021 18:10:24 +0800 Subject: [PATCH 2/5] Created an entry in What's New --- docs/src/whatsnew/latest.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 3caf386ef6..81b63a8fd3 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -52,6 +52,9 @@ This document explains the changes made to Iris for this release printing these objects skips metadata elements that are set to None or an empty string or dictionary. (:pull:`4040`) +#. `@Badboy-16`_ implemented a ``CubeList.copy()`` method to return a + ``CubeList`` object instead of a ``list``. (:pull:`4094`) + 🐛 Bugs Fixed ============= @@ -189,4 +192,4 @@ This document explains the changes made to Iris for this release .. _Python 3.8: https://www.python.org/downloads/release/python-380/ .. _README.md: https://github.com/SciTools/iris#----- .. _xxhash: http://cyan4973.github.io/xxHash/ -.. _conda-lock: https://github.com/conda-incubator/conda-lock \ No newline at end of file +.. _conda-lock: https://github.com/conda-incubator/conda-lock From 762ef99ea59865e0ea3e6e8428dab5e3ca51262c Mon Sep 17 00:00:00 2001 From: Yang Yunyi Date: Thu, 27 May 2021 18:58:59 +0800 Subject: [PATCH 3/5] Added test for CubeList.copy() --- lib/iris/tests/test_cube.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/iris/tests/test_cube.py b/lib/iris/tests/test_cube.py index 337bcb508a..31cd142128 100644 --- a/lib/iris/tests/test_cube.py +++ b/lib/iris/tests/test_cube.py @@ -88,5 +88,14 @@ class Terry: self.assertIs(cube.__ne__(Terry()), NotImplemented) +class Test_CubeList_copy(tests.IrisTest): + def setUp(self): + self.cube_list = iris.cube.CubeList() + self.copied_cube_list = self.cube_list.copy() + + def test_copy(self): + self.assertIsInstance(self.copied_cube_list, iris.cube.CubeList) + + if __name__ == "__main__": tests.main() From eb17561c66aae440df5f56182a37e492306e7d27 Mon Sep 17 00:00:00 2001 From: Yang Yunyi Date: Thu, 27 May 2021 22:08:30 +0800 Subject: [PATCH 4/5] Moved CubeList.copy() test into the correct file --- lib/iris/tests/test_cube.py | 9 --------- lib/iris/tests/unit/cube/test_CubeList.py | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/iris/tests/test_cube.py b/lib/iris/tests/test_cube.py index 31cd142128..337bcb508a 100644 --- a/lib/iris/tests/test_cube.py +++ b/lib/iris/tests/test_cube.py @@ -88,14 +88,5 @@ class Terry: self.assertIs(cube.__ne__(Terry()), NotImplemented) -class Test_CubeList_copy(tests.IrisTest): - def setUp(self): - self.cube_list = iris.cube.CubeList() - self.copied_cube_list = self.cube_list.copy() - - def test_copy(self): - self.assertIsInstance(self.copied_cube_list, iris.cube.CubeList) - - if __name__ == "__main__": tests.main() diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index 2e7b110d60..82c4280fff 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -602,5 +602,14 @@ def test_realise_data(self): ) +class Test_CubeList_copy(tests.IrisTest): + def setUp(self): + self.cube_list = iris.cube.CubeList() + self.copied_cube_list = self.cube_list.copy() + + def test_copy(self): + self.assertIsInstance(self.copied_cube_list, iris.cube.CubeList) + + if __name__ == "__main__": tests.main() From 8b542307882379ed9811a3356126b3a3262a2326 Mon Sep 17 00:00:00 2001 From: Yang Yunyi Date: Thu, 27 May 2021 22:10:51 +0800 Subject: [PATCH 5/5] Creating a link to the username --- docs/src/whatsnew/latest.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 81b63a8fd3..538b6b1142 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -173,6 +173,7 @@ This document explains the changes made to Iris for this release core dev names are automatically included by the common_links.inc: .. _@akuhnregnier: https://github.com/akuhnregnier +.. _@Badboy-16: https://github.com/Badboy-16 .. _@gcaria: https://github.com/gcaria .. _@MHBalsmeier: https://github.com/MHBalsmeier