nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: shapely/shapely
Pull request #2120 (2024-08-22 14:21:39)

FIX: mapping of empty point
Fixes https://github.com/shapely/shapely/issues/1807

Empty points coordinates are convert to an empty tuple. This is in line with how GEOS and PostGIS serialize empty points as GeoJSON (`{"type":"Point","coordinates":[]}`.

jorisvandenbossche: @Oreilles could you also update there with latest main (and add a note to CHANGES.txt)?
Oreilles: Should be good 👍 
coveralls: ## Pull Request Test Coverage Report for [Build 10956227604](https://coveralls.io/builds/69908308)


### Details

* **2** of **2**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.3%**) to **87.861%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/69908308/badge)](https://coveralls.io/builds/69908308) |
| :-- | --: |
| Change from base [Build 10899958577](https://coveralls.io/builds/69836105): |  0.3% |
| Covered Lines: | 2613 |
| Relevant Lines: | 2974 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index efe04c8..f621852 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,7 @@ Bug fixes:
 
 - Prevent crash when serializing a number > 1e100 to WKT with GEOS < 3.13. (#1907)
 - Fixes GeoJSON serialization of empty points (#2118)
+- Fixes `__geo_interface__` handling of empty points (#2120)
 
 Improvements:
 
diff --git a/shapely/geometry/point.py b/shapely/geometry/point.py
index ccdd5c6..1816b67 100644
--- a/shapely/geometry/point.py
+++ b/shapely/geometry/point.py
@@ -116,7 +116,8 @@ class Point(BaseGeometry):
     @property
     def __geo_interface__(self):
         """Return a GeoJSON-like mapping of the Point geometry."""
-        return {"type": "Point", "coordinates": self.coords[0]}
+        coords = self.coords
+        return {"type": "Point", "coordinates": coords[0] if len(coords) > 0 else ()}
 
     def svg(self, scale_factor=1.0, fill_color=None, opacity=None):
         """Return SVG circle element for the Point geometry.


Test patch:
diff --git a/shapely/tests/geometry/test_point.py b/shapely/tests/geometry/test_point.py
index b8af140..9995c89 100644
--- a/shapely/tests/geometry/test_point.py
+++ b/shapely/tests/geometry/test_point.py
@@ -151,6 +151,8 @@ class TestPoint:
         assert p_null.coords[:] == []
         assert p_null.area == 0.0
 
+        assert p_null.__geo_interface__ == {"type": "Point", "coordinates": ()}
+
     def test_coords(self):
         # From Array.txt
         p = Point(0.0, 0.0, 1.0)
Repository: shapely/shapely
Pull request #2224 (2025-02-15 15:01:20)

ERR: Add better error message for (not) providing offsets in from_ragged_array
Closes https://github.com/shapely/shapely/issues/1794

coveralls: ## Pull Request Test Coverage Report for [Build 13346139667](https://coveralls.io/builds/72257339)


### Details

* **5** of **5**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.3%**) to **87.758%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/72257339/badge)](https://coveralls.io/builds/72257339) |
| :-- | --: |
| Change from base [Build 13346054967](https://coveralls.io/builds/72257287): |  0.3% |
| Covered Lines: | 2595 |
| Relevant Lines: | 2957 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/shapely/_ragged_array.py b/shapely/_ragged_array.py
index a1af4a0..ca63d51 100644
--- a/shapely/_ragged_array.py
+++ b/shapely/_ragged_array.py
@@ -422,11 +422,18 @@ def from_ragged_array(geometry_type, coords, offsets=None):
     coords = np.asarray(coords, dtype="float64")
 
     if geometry_type == GeometryType.POINT:
-        assert offsets is None or len(offsets) == 0
+        if not (offsets is None or len(offsets) == 0):
+            raise ValueError("'offsets' should not be provided for geometry type Point")
         return _point_from_flatcoords(coords)
+
+    if offsets is None:
+        raise ValueError(
+            "'offsets' must be provided for any geometry type except for Point"
+        )
+
     if geometry_type == GeometryType.LINESTRING:
         return _linestring_from_flatcoords(coords, *offsets)
-    if geometry_type == GeometryType.POLYGON:
+    elif geometry_type == GeometryType.POLYGON:
         return _polygon_from_flatcoords(coords, *offsets)
     elif geometry_type == GeometryType.MULTIPOINT:
         return _multipoint_from_flatcoords(coords, *offsets)


Test patch:
diff --git a/shapely/tests/test_ragged_array.py b/shapely/tests/test_ragged_array.py
index c11e6c8..8507152 100644
--- a/shapely/tests/test_ragged_array.py
+++ b/shapely/tests/test_ragged_array.py
@@ -443,3 +443,17 @@ def test_from_ragged_incorrect_rings_unclosed():
         shapely.from_ragged_array(
             shapely.GeometryType.POLYGON, coords, (offsets1, offsets2)
         )
+
+
+def test_from_ragged_wrong_offsets():
+    with pytest.raises(ValueError, match="'offsets' must be provided"):
+        shapely.from_ragged_array(
+            shapely.GeometryType.LINESTRING, np.array([[0, 0], [0, 1]])
+        )
+
+    with pytest.raises(ValueError, match="'offsets' should not be provided"):
+        shapely.from_ragged_array(
+            shapely.GeometryType.POINT,
+            np.array([[0, 0], [0, 1]]),
+            offsets=(np.array([0, 1]),),
+        )
Repository: shapely/shapely
Pull request #2238 (2025-02-25 09:18:11)

FIX: allow .coords to include M coordinates if present
This minor fix is an oversight related to #2234 where M coordinates should appear in the `.coords` property if present in the geometry.

jorisvandenbossche: Good catch!

This also closes https://github.com/shapely/shapely/issues/2171 then, I think

Patch:
diff --git a/shapely/coords.py b/shapely/coords.py
index daeb066..146c966 100644
--- a/shapely/coords.py
+++ b/shapely/coords.py
@@ -8,10 +8,13 @@ class CoordinateSequence:
 
     Examples
     --------
-      >>> from shapely.wkt import loads
-      >>> g = loads('POINT (0.0 0.0)')
-      >>> list(g.coords)
-      [(0.0, 0.0)]
+    >>> from shapely.wkt import loads
+    >>> g = loads('POINT (0.0 0.0)')
+    >>> list(g.coords)
+    [(0.0, 0.0)]
+    >>> g = loads('POINT M (1 2 4)')
+    >>> g.coords[:]
+    [(1.0, 2.0, 4.0)]
 
     """
 
diff --git a/shapely/geometry/base.py b/shapely/geometry/base.py
index 79b6bc2..c394e64 100644
--- a/shapely/geometry/base.py
+++ b/shapely/geometry/base.py
@@ -28,6 +28,8 @@ GEOMETRY_TYPES = [
     "GeometryCollection",
 ]
 
+_geos_ge_312 = shapely.geos_version >= (3, 12, 0)
+
 
 def geom_factory(g, parent=None):
     """Create a Shapely geometry instance from a pointer to a GEOS geometry.
@@ -216,7 +218,9 @@ class BaseGeometry(shapely.Geometry):
     @property
     def coords(self):
         """Access to geometry's coordinates (CoordinateSequence)."""
-        coords_array = shapely.get_coordinates(self, include_z=self.has_z)
+        has_z = self.has_z
+        has_m = self.has_m if _geos_ge_312 else False
+        coords_array = shapely.get_coordinates(self, include_z=has_z, include_m=has_m)
         return CoordinateSequence(coords_array)
 
     @property


Test patch:
diff --git a/shapely/tests/geometry/test_coords.py b/shapely/tests/geometry/test_coords.py
index 1477c20..1132005 100644
--- a/shapely/tests/geometry/test_coords.py
+++ b/shapely/tests/geometry/test_coords.py
@@ -1,8 +1,17 @@
 import numpy as np
 import pytest
 
-from shapely import LineString
-from shapely.tests.common import line_string, line_string_z, point, point_z
+from shapely import LineString, geos_version
+from shapely.tests.common import (
+    line_string,
+    line_string_m,
+    line_string_z,
+    line_string_zm,
+    point,
+    point_m,
+    point_z,
+    point_zm,
+)
 
 
 class TestCoords:
@@ -100,3 +109,19 @@ def test_coords_array_copy(geom):
             np.array(coord_seq, copy=False)
     else:
         assert np.array(coord_seq, copy=False) is np.array(coord_seq, copy=False)
+
+
+@pytest.mark.skipif(geos_version < (3, 12, 0), reason="GEOS < 3.12")
+def test_coords_with_m():
+    assert point_m.coords[:] == [(2.0, 3.0, 5.0)]
+    assert point_zm.coords[:] == [(2.0, 3.0, 4.0, 5.0)]
+    assert line_string_m.coords[:] == [
+        (0.0, 0.0, 1.0),
+        (1.0, 0.0, 2.0),
+        (1.0, 1.0, 3.0),
+    ]
+    assert line_string_zm.coords[:] == [
+        (0.0, 0.0, 4.0, 1.0),
+        (1.0, 0.0, 4.0, 2.0),
+        (1.0, 1.0, 4.0, 3.0),
+    ]