nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: shapely/shapely
Pull request #1786 (2023-03-15 02:59:51)

Check for any `MultiPolygon`s when constructing a `MultiPolygon`
Currently, the `MultiPolygon` constructor only validates the type of the first element of the `polygons` input. When a later element does not have the correct type, things silently fail.

jorisvandenbossche: Hey @ianwilliamson would you have time to add a small test for this? 
coveralls: ## Pull Request Test Coverage Report for [Build 11872818052](https://coveralls.io/builds/70903193)


### Details

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

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/70903193/badge)](https://coveralls.io/builds/70903193) |
| :-- | --: |
| Change from base [Build 11870649212](https://coveralls.io/builds/70902350): |  0.3% |
| Covered Lines: | 2562 |
| Relevant Lines: | 2923 |

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


Patch:
diff --git a/shapely/geometry/multipolygon.py b/shapely/geometry/multipolygon.py
index 42b000e..073fd86 100644
--- a/shapely/geometry/multipolygon.py
+++ b/shapely/geometry/multipolygon.py
@@ -66,7 +66,7 @@ class MultiPolygon(BaseMultipartGeometry):
 
         # This function does not accept sequences of MultiPolygons: there is
         # no implicit flattening.
-        if isinstance(polygons[0], MultiPolygon):
+        if any(isinstance(p, MultiPolygon) for p in polygons):
             raise ValueError("Sequences of multi-polygons are not valid arguments")
 
         subs = []


Test patch:
diff --git a/shapely/tests/geometry/test_multipolygon.py b/shapely/tests/geometry/test_multipolygon.py
index 42e55a5..0494951 100644
--- a/shapely/tests/geometry/test_multipolygon.py
+++ b/shapely/tests/geometry/test_multipolygon.py
@@ -126,6 +126,7 @@ class TestMultiPolygon(MultiGeometryTestCase):
 
 def test_fail_list_of_multipolygons():
     """A list of multipolygons is not a valid multipolygon ctor argument"""
+    poly = Polygon([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)])
     multi = MultiPolygon(
         [
             (
@@ -137,6 +138,9 @@ def test_fail_list_of_multipolygons():
     with pytest.raises(ValueError):
         MultiPolygon([multi])
 
+    with pytest.raises(ValueError):
+        MultiPolygon([poly, multi])
+
 
 def test_numpy_object_array():
     geom = MultiPolygon(