Skip to content

Commit

Permalink
made dataless copy opt-in behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Dec 17, 2024
1 parent 063e45b commit 79d7d67
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
7 changes: 2 additions & 5 deletions lib/iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -187,20 +186,18 @@ 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.

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',}
Expand Down Expand Up @@ -846,4 +843,4 @@ def use_plugin(plugin_name):
importlib.import_module(f"iris.plugins.{plugin_name}")


MAINTAIN_DATA = "MAINTAINDATA"
DATALESS_COPY = "NONE"
11 changes: 4 additions & 7 deletions lib/iris/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 79d7d67

Please sign in to comment.