Deprecate ctypes attribute and array interface#955
Conversation
| coords = geometry.LineString([[12, 34], [56, 78]]).coords | ||
| with pytest.warns(ShapelyDeprecationWarning, match="ctypes"): | ||
| coords.ctypes |
There was a problem hiding this comment.
@jorisvandenbossche would the following suffice?
| coords = geometry.LineString([[12, 34], [56, 78]]).coords | |
| with pytest.warns(ShapelyDeprecationWarning, match="ctypes"): | |
| coords.ctypes | |
| with pytest.warns(ShapelyDeprecationWarning, match="ctypes"): | |
| geometry.LineString().coords.ctypes |
I feel like the unused coordinate values are slightly distracting. Or maybe test the CoordinateSequence class only?
Also, what would you think about a minimal docstring for the test?
There was a problem hiding this comment.
Added a docstring (and also fixed the test name, that was a copy/paster error).
geometry.LineString().coords.ctypes actually doesn't work, because for an empty geometry the coords attribute returns an empty list instead of a CoordinateSequence object (to me this feels a bit like a bug, but is done on purpose in the code).
| import numpy as np | ||
|
|
||
| line = LineString(((1.0, 2.0), (3.0, 4.0))) | ||
| with pytest.warns(ShapelyDeprecationWarning, match="array interface"): |
There was a problem hiding this comment.
Today I learned about the match keyword argument! I'm going to use this more often.
sgillies
left a comment
There was a problem hiding this comment.
Seems right to me. I left two suggestions inline, one about unnecessary coordinate args for geometry constructors, and one about docstrings. I won't insist in either case. The docstrings are not absolutely necessary since these are transitional tests.
tomplex
left a comment
There was a problem hiding this comment.
I don't have much to add here - it all looks good to me.
Deprecating the ctypes attribute and the array_interface.
See https://github.com/shapely/shapely-rfc/pull/1/files#diff-554e526a1f0fe104169383c013e37a7cR360 for the rationale
The array interface is kept intact for the CoordinateSequence, so occurence of
np.array(geom)can be replaced withnp.array(geom.coords).(we should eventually implement this differently (not using ctypes), but that can be left for later or even for Shapely 2.0)