-
Notifications
You must be signed in to change notification settings - Fork 284
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
ENH: Shared data between cube slices #2549
Conversation
Hi @cpelley i'm interested to understand
why is this test affected, when none of the others seems to be more to follow soon |
The points has been passed to point.setter of the DimCoord so it has been made read-only (the other tests involving DimCoord take a copy of points). This PR makes setting the points take a view of the points supplied, making it consistent with the AuxCoords. Here is the current behaviour of master: >>> import iris.coords
>>> import numpy as np
>>> points = np.array([1, 2, 3, 4])
>>> auxcoord = iris.coords.AuxCoord(points)
>>> points[0] = 10
>>> auxcoord.points
array([10, 2, 3, 4])
>>> points = np.array([1, 2, 3, 4])
>>> points = np.array([1, 2, 3, 4])
>>> dimcoord = iris.coords.DimCoord(points)
>>> points[0] = -1
>>> dimcoord.points
array([1, 2, 3, 4]) We make DimCoord consistent in returning a view as the AuxCoord, except that DimCoord arrays are read-only: >>> points = np.array([1, 2, 3, 4])
>>> dimxcoord = iris.coords.DimCoord(points)
>>> points[0]
1
>>> points[0] = -10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: assignment destination is read-only The fact that AuxCoord arrays are not read-only is a bug (see the ticket description). I can happily make it read-only as part of this PR. |
@marqh perhaps if I re-introduced the tests would clarify? |
hi @cpelley i agree with the principal of this approach, I think that providing the user with the option to opt into passing array references rather than copies brings benefit whist protecting naive users. I'm not sure about the name could |
@marqh, as requested I have removed the changes which make the DimCoord setter for points and bounds views of their supplied arrays. |
From an offline discussion, given that coordinate data views has been ruled out and the motivation for them is the same as this (cube data views). I think it's safe to say that getting this into iris for this milestone is unlikely. Pulling it out for now so as not to detract from putting out the release. |
8552f65
to
239245b
Compare
Based on off-line discussion:
Thanks @marqh |
239245b
to
e415f68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favour of this change
I have one minor requested change, them I aim to merge this
lib/iris/coords.py
Outdated
@@ -1521,7 +1526,7 @@ def points(self): | |||
|
|||
@points.setter | |||
def points(self, points): | |||
points = np.array(points, ndmin=1) | |||
points = np.array(points, ndmin=1, copy=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that I would prefer to not introduce this copy flag to dim_coords just yet
i think the benefit is less, so perhaps we can look at this again
lib/iris/cube.py
Outdated
# Realise the data if is hasn't already been as sharing lazy data is | ||
# not right now possible or a usecase understood. | ||
if self.has_lazy_data(): | ||
self.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will/may show the data, i woudl prefer
_ = cube.data
😃 Thanks @marqh |
@share_data.setter | ||
def share_data(self, value): | ||
# Realise the data if is hasn't already been as sharing lazy data is | ||
# not right now possible or a usecase understood. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpelley This comment doesn't make sense.
# Realise the data if is hasn't already been as sharing lazy data is | ||
# not right now possible or a usecase understood. | ||
if self.has_lazy_data(): | ||
_ = self.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpelley I really disagree that if you want to share the data, you need to realise the data here at this point in the property. This is bad practice IMHO.
You're effectively applying a side-effect here to suit your specific needs. Surely, if you do require to realise the data, then it should only occur in the code base where share_data
is True
and it actually needs the data at that point in time. We're now in the situation where we've thrown away any laziness, all because we've set this property .... and the kicker is that the data is loaded regardless of the value
passed ... I find that totally bizarre!
Loading the data is a BIG deal, and it's not even advertised in the doc-string. Why?
... and where's the documentation to cover this change, so that users know what's happening? No doc-string, no documentation. We really need to be always conscious of our users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello @bjlittle
I explicitly asked for this to be included, as part of my review of the code, so I am more culpable than @cpelley
I think that you are right that this should only be implemented for setting to True
I think that a better docstring would help
I have created #2584, pointed at 1.13.x, as a proposed 'bug fix' for these concerns
I have put up the changes here to demonstrate the UI (tests will follow an agreement in principle of the changes).
Demonstrate the UI of this PR:
Replaces #2261, #1992
These changes are shown to be readily applicable when switching to dask too link
NOT FOR MERGING