Skip to content

Commit

Permalink
Add a method to return a CubeList from CubeList.copy() (#4094)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Badboy-16 authored May 27, 2021
1 parent 956df99 commit 6cab227
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down Expand Up @@ -170,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

Expand All @@ -189,4 +193,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
.. _conda-lock: https://github.com/conda-incubator/conda-lock
7 changes: 7 additions & 0 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
9 changes: 9 additions & 0 deletions lib/iris/tests/unit/cube/test_CubeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 6cab227

Please sign in to comment.