Deprecate asShape (CachingGeometryProxy adapter classes)#926
Deprecate asShape (CachingGeometryProxy adapter classes)#926sgillies merged 3 commits intoshapely:masterfrom
Conversation
shapely/geometry/geo.py
Outdated
|
|
||
| if geom_type == "point": | ||
| return asPoint(ob["coordinates"]) | ||
| return _asPoint(ob["coordinates"]) |
There was a problem hiding this comment.
This is to avoid a duplicate warning coming from asPoint (the alternative is to only warn in asPoint with a more general warning message, and that warning will the also be seen when calling asShape)
|
Excellent, @jorisvandenbossche . I can't think of a reason not to eliminate the adapter classes in 2.0. There's a lot of code there that we won't want to maintain anymore and it only exists to support a kind of mutability. How about warning from the adapter constructors, mentioning deprecation of the class and the factory functions (asShape, asPoint, &c)? |
OK, doing a warning only in the class + a general message so it is valid for all possible ways to construct it sounds good. |
|
Updated the warning message and location. If that looks good, then will do the same for the other geometry types. |
| self.assertIsInstance(shape, MultiPolygonAdapter) | ||
| self.assertEqual(len(shape.geoms), 1) | ||
|
|
||
| def test_geointerface(self): |
There was a problem hiding this comment.
I copied the test above, and adapted it to use shape instead of asShape, as there didn't seem a dedicated test for shape for all different geometry types.
|
|
||
| @unittest.skipIf(not numpy, 'numpy not installed') | ||
| def test_multipoint(self): | ||
| arr = numpy.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]]) |
There was a problem hiding this comment.
Also here, copied the tests above but adapted using the normal constructor, to ensure we keep tests for this functionality when the adapter tests are removed.
|
@sgillies ok, updated for all geometry types. This is ready for review / merge. |
|
Excellent! |
Deprecating the adapter classes that create geometry-like proxy objects with coordinates stored in external objects (xref shapely/shapely-rfc#1).
I again started with the Point geometry to check if the workflow looks good.
There are however multiple ways to create those objects. For points, you have the general
asShapeandasPoint, but in principle also thePointAdapterclass constructor (but I don't know whether those are regarded as public API?).The way I did it now is to add a deprecation warning to both
asShapeandasPoint, so the message can be specific. Bu there are certainly other ways to do it as well.