Skip to content

Make MeshCoords immutable and sync updates with the attached mesh #6405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
14 changes: 14 additions & 0 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collections import namedtuple
from collections.abc import Container
import copy
from datetime import datetime
from functools import lru_cache
from itertools import zip_longest
import operator
Expand Down Expand Up @@ -98,6 +99,8 @@ def __init__(
if not hasattr(self, "_metadata_manager"):
self._metadata_manager = metadata_manager_factory(BaseMetadata)

self._mesh_parents = []

#: CF standard name of the quantity that the metadata represents.
self.standard_name = standard_name

Expand Down Expand Up @@ -569,6 +572,17 @@ def reindent_data_string(text, n_indent):

return "\n".join(output_lines)

def __setattr__(self, key, value):
if getattr(self, "_mesh_parents", None) is not None:
for parent in self._mesh_parents:
parent.timestamp = datetime.now()

prop = getattr(type(self), key, None)
if isinstance(prop, property):
prop.__set__(self, value)
else:
super.__setattr__(self, key, value)

def __str__(self):
return self.summary()

Expand Down
2 changes: 1 addition & 1 deletion lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2785,7 +2785,7 @@ def shape(self) -> tuple[int, ...]:

@property
def dtype(self):
"""The data type of the values in the data array of this :class:`~iris.cube.Cube`."""
"""The dtype of the values in the data array of this :class:`~iris.cube.Cube`."""
return self._data_manager.dtype

@property
Expand Down
Loading
Loading