-
Notifications
You must be signed in to change notification settings - Fork 605
ENH: add copy=None to CoordinateSequence.__array__ #2053
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
Conversation
|
Thanks! I had noted this as a TODO item in #1972, but didn't yet get to it (and didn't expect our CI to fail for it, but so this is a good reminder ;)) Ideally we would honor the |
|
I had a play with various copy=True/False/None versions, and it all seems minor impact, mostly because CoordinateSequence objects aren't really used as separate objects. Each A simple implementation would be: def __array__(self, dtype=None, copy=None):
if copy:
return self._coords.copy()
return self._coordsthen tested (somewhere): def test_coords_array():
coord_seq = point.coords
assert np.array(coord_seq) is not np.array(coord_seq)
assert np.array(coord_seq, copy=False) is np.array(coord_seq, copy=False)
assert np.array(coord_seq, copy=True) is not np.array(coord_seq, copy=True) |
Pull Request Test Coverage Report for Build 9087673717Details
💛 - Coveralls |
|
Hmm, yes, it depends on how you interpret the CoordinateSequence object. Is that just a wrapper around an already materialized numpy array Because in the former case, you can indeed say that Now, since this CoordinateSequence class is a separate object from the Geometry objects, it might be that the former interpretation is the only viable one. |
|
From The |
|
Any further review/comment @jorisvandenbossche ? |
jorisvandenbossche
left a comment
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.
Sorry, this fell off my radar. Let's get this in to fix the CI failures
| elif copy is True: | ||
| return self._coords.copy() |
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.
On thing I am still wondering: if we say that a copy is always created (in the error message above), then maybe we should not actually do the explicit copy here?
Of course, if one saved the .coords separately, one might still expect this actual copy ..
coords = geom.coords
coords_arr1 = np.asarray(coords, copy=True)
coords_arr2 = np.asarray(coords, copy=True)
i.e. one would expect in the case above that those two numpy arrays are not views of each other .. So I assume the above explicit copy is fine. We are just a bit inconsistent about the copy=False vs copy=True
Recent CI failures have picked up a recent NumPy 2.0 change, noted in the migration guide under "Adapting to changes in the copy keyword".
A simple fix appears to be to simply add
copy=Noneto the__array__signature. This value is not used by the method.Here is an example failure:
Note that test failures with macos in this PR are unrelated.