Skip to content

Commit 6cab227

Browse files
authored
Add a method to return a CubeList from CubeList.copy() (#4094)
* Add a method to return a CubeList from CubeList.copy() * Created an entry in What's New * Added test for CubeList.copy() * Moved CubeList.copy() test into the correct file * Creating a link to the username
1 parent 956df99 commit 6cab227

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ This document explains the changes made to Iris for this release
5252
printing these objects skips metadata elements that are set to None or an
5353
empty string or dictionary. (:pull:`4040`)
5454

55+
#. `@Badboy-16`_ implemented a ``CubeList.copy()`` method to return a
56+
``CubeList`` object instead of a ``list``. (:pull:`4094`)
57+
5558

5659
🐛 Bugs Fixed
5760
=============
@@ -170,6 +173,7 @@ This document explains the changes made to Iris for this release
170173
core dev names are automatically included by the common_links.inc:
171174
172175
.. _@akuhnregnier: https://github.com/akuhnregnier
176+
.. _@Badboy-16: https://github.com/Badboy-16
173177
.. _@gcaria: https://github.com/gcaria
174178
.. _@MHBalsmeier: https://github.com/MHBalsmeier
175179

@@ -189,4 +193,4 @@ This document explains the changes made to Iris for this release
189193
.. _Python 3.8: https://www.python.org/downloads/release/python-380/
190194
.. _README.md: https://github.com/SciTools/iris#-----
191195
.. _xxhash: http://cyan4973.github.io/xxHash/
192-
.. _conda-lock: https://github.com/conda-incubator/conda-lock
196+
.. _conda-lock: https://github.com/conda-incubator/conda-lock

lib/iris/cube.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,13 @@ def realise_data(self):
707707
"""
708708
_lazy.co_realise_cubes(*self)
709709

710+
def copy(self):
711+
"""
712+
Return a CubeList when CubeList.copy() is called.
713+
"""
714+
if type(self) == CubeList:
715+
return deepcopy(self)
716+
710717

711718
def _is_single_item(testee):
712719
"""

lib/iris/tests/unit/cube/test_CubeList.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,5 +602,14 @@ def test_realise_data(self):
602602
)
603603

604604

605+
class Test_CubeList_copy(tests.IrisTest):
606+
def setUp(self):
607+
self.cube_list = iris.cube.CubeList()
608+
self.copied_cube_list = self.cube_list.copy()
609+
610+
def test_copy(self):
611+
self.assertIsInstance(self.copied_cube_list, iris.cube.CubeList)
612+
613+
605614
if __name__ == "__main__":
606615
tests.main()

0 commit comments

Comments
 (0)