From 79d7d6720b3eb63b320074dcced33480ba02add9 Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Tue, 17 Dec 2024 10:22:20 +0000 Subject: [PATCH] made dataless copy opt-in behaviour --- lib/iris/__init__.py | 7 ++----- lib/iris/_data_manager.py | 11 ++++------- lib/iris/coords.py | 3 +-- lib/iris/tests/unit/cube/test_Cube.py | 11 +++++------ 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/iris/__init__.py b/lib/iris/__init__.py index 37b6a89c9a..5a6920d4ce 100644 --- a/lib/iris/__init__.py +++ b/lib/iris/__init__.py @@ -148,7 +148,6 @@ def __init__( datum_support=False, pandas_ndim=False, save_split_attrs=False, - dataless_cube=False, ): """Container for run-time options controls. @@ -187,7 +186,6 @@ def __init__( self.__dict__["datum_support"] = datum_support self.__dict__["pandas_ndim"] = pandas_ndim self.__dict__["save_split_attrs"] = save_split_attrs - self.__dict__["dataless_cube"] = dataless_cube # TODO: next major release: set IrisDeprecation to subclass # DeprecationWarning instead of UserWarning. @@ -195,12 +193,11 @@ def __init__( def __repr__(self): # msg = ('Future(example_future_flag={})') # return msg.format(self.example_future_flag) - msg = "Future(datum_support={}, pandas_ndim={}, save_split_attrs={}, dataless_cubes={})" + msg = "Future(datum_support={}, pandas_ndim={}, save_split_attrs={})" return msg.format( self.datum_support, self.pandas_ndim, self.save_split_attrs, - self.dataless_cube, ) # deprecated_options = {'example_future_flag': 'warning',} @@ -846,4 +843,4 @@ def use_plugin(plugin_name): importlib.import_module(f"iris.plugins.{plugin_name}") -MAINTAIN_DATA = "MAINTAINDATA" +DATALESS_COPY = "NONE" diff --git a/lib/iris/_data_manager.py b/lib/iris/_data_manager.py index d27d759161..00db3ff329 100644 --- a/lib/iris/_data_manager.py +++ b/lib/iris/_data_manager.py @@ -159,18 +159,15 @@ def _deepcopy(self, memo, data=None): """ shape = None try: - if iris.FUTURE.dataless_cube and data is None: - shape = self.shape - elif ( - iris.FUTURE.dataless_cube - and type(data) is str - and data == iris.MAINTAIN_DATA - ) or (data is None): + if data is None: # Copy the managed data. if self.has_lazy_data(): data = copy.deepcopy(self._lazy_array, memo) else: data = self._real_array.copy() + elif type(data) is str and data == iris.DATALESS_COPY: + shape = self.shape + data = None else: # Check that the replacement data is valid relative to # the currently managed data. diff --git a/lib/iris/coords.py b/lib/iris/coords.py index bdd2ac231e..06a271cbba 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -2708,8 +2708,7 @@ def __deepcopy__(self, memo): # numpydoc ignore=SS02 """ new_coord = copy.deepcopy(super(), memo) # Ensure points and bounds arrays are read-only. - if not (new_coord._values_dm.data is None and iris.FUTURE.dataless_cube): - new_coord._values_dm.data.flags.writeable = False + new_coord._values_dm.data.flags.writeable = False if new_coord._bounds_dm is not None: new_coord._bounds_dm.data.flags.writeable = False return new_coord diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index cf832719a0..54fb49ea73 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -2090,12 +2090,11 @@ def test_copy_new_data(self): _shared_utils.assert_array_equal(new_cube.data, new_data) def test_copy_remove_data(self): - with iris.FUTURE.context(dataless_cube=True): - cube = stock.simple_3d() - new_cube = cube.copy() - assert new_cube.metadata == cube.metadata - assert new_cube.data is None - assert new_cube.shape == cube.shape + cube = stock.simple_3d() + new_cube = cube.copy(iris.DATALESS_COPY) + assert new_cube.metadata == cube.metadata + assert new_cube.data is None + assert new_cube.shape == cube.shape def test__masked_emptymask(self): cube = Cube(ma.array([0, 1]))