nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: Toblerity/Shapely
Pull request #700 (2019-04-07 20:00:19)

#695: fix segfault and unicode errors for non text parameter wkt loads
fix for https://github.com/Toblerity/Shapely/issues/695

coveralls: 
[![Coverage Status](https://coveralls.io/builds/22654118/badge)](https://coveralls.io/builds/22654118)

Coverage increased (+0.01%) to 80.712% when pulling **f59850295ea4459c88f70453194d8702db7d9f3f on tbicr:695-fix-segfault-and-unxepected-error-for-wkt-non-text-load** into **5157665a883a273e76768968b7db3a1f1e1be16a on Toblerity:master**.


Patch:
diff --git a/shapely/geos.py b/shapely/geos.py
index 149a898..deb6fff 100644
--- a/shapely/geos.py
+++ b/shapely/geos.py
@@ -21,6 +21,11 @@ from .errors import WKBReadingError, WKTReadingError, TopologicalError, Predicat
 # Add message handler to this module's logger
 LOG = logging.getLogger(__name__)
 
+if sys.version_info[0] >= 3:
+    text_types = str
+else:
+    text_types = (str, unicode)
+
 # Find and load the GEOS and C libraries
 # If this ever gets any longer, we'll break it into separate modules
 
@@ -257,9 +262,12 @@ class WKTReader(object):
 
     def read(self, text):
         """Returns geometry from WKT"""
+        if not isinstance(text, text_types):
+            raise TypeError("Only str is accepted.")
         if sys.version_info[0] >= 3:
-            text = text.encode('ascii')
-        geom = self._lgeos.GEOSWKTReader_read(self._reader, c_char_p(text))
+             text = text.encode()
+        c_string = c_char_p(text)
+        geom = self._lgeos.GEOSWKTReader_read(self._reader, c_string)
         if not geom:
             raise WKTReadingError(
                 "Could not create geometry because of errors "


Test patch:
diff --git a/tests/test_geos_err_handler.py b/tests/test_geos_err_handler.py
index cf7e7d8..ceea3ab 100644
--- a/tests/test_geos_err_handler.py
+++ b/tests/test_geos_err_handler.py
@@ -1,4 +1,5 @@
 import logging
+import sys
 
 import pytest
 
@@ -37,6 +38,17 @@ def test_error_handler(tmpdir):
     assert "third argument of GEOSProject_r must be Point*" in log
 
 
+def test_error_handler_wrong_type():
+    with pytest.raises(TypeError):
+        loads(1)
+
+
+@pytest.mark.skipif(sys.version_info[0] < 3, reason='accept str and unicode for python2 and str for python3')
+def test_error_handler_for_bytes():
+    with pytest.raises(TypeError):
+        loads(b'POINT (10 10)')
+
+
 def test_info_handler(tmpdir):
     logger = logging.getLogger('shapely.geos')
     logfile = str(tmpdir.join('test_error.log'))
Repository: Toblerity/Shapely
Pull request #731 (2019-06-15 03:42:30)

Exterior of an empty polygon is equivalent to LinearRing()
Fix for https://github.com/Toblerity/Shapely/issues/712 as was suggested by @sgillies.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/24012178/badge)](https://coveralls.io/builds/24012178)

Coverage decreased (-0.2%) to 80.51% when pulling **e99a269e3ace53b5ad2cbc3d8fbca87378a5bb2e on drnextgis:gh712-empty-polygon** into **57286ee5a34c9ab15e60030c73ea33d40e62828a on Toblerity:master**.


Patch:
diff --git a/shapely/geometry/polygon.py b/shapely/geometry/polygon.py
index 24a02b0..e261350 100644
--- a/shapely/geometry/polygon.py
+++ b/shapely/geometry/polygon.py
@@ -245,7 +245,7 @@ class Polygon(BaseGeometry):
     @property
     def exterior(self):
         if self.is_empty:
-            return None
+            return LinearRing()
         elif self._exterior is None or self._exterior() is None:
             g = lgeos.GEOSGetExteriorRing(self._geom)
             ring = LinearRing()
@@ -311,7 +311,7 @@ class Polygon(BaseGeometry):
 
     @property
     def __geo_interface__(self):
-        if not self.exterior:
+        if self.exterior == LinearRing():
             coords = []
         else:
             coords = [tuple(self.exterior.coords)]


Test patch:
diff --git a/tests/test_polygon.py b/tests/test_polygon.py
index 057a3d9..43f7048 100644
--- a/tests/test_polygon.py
+++ b/tests/test_polygon.py
@@ -257,6 +257,10 @@ class PolygonTestCase(unittest.TestCase):
             Polygon(coords),
             Polygon.from_bounds(xmin, ymin, xmax, ymax))
 
+    def test_empty_polygon_exterior(self):
+        p = Polygon()
+        assert p.exterior == LinearRing()
+
 
 def test_suite():
     return unittest.TestLoader().loadTestsFromTestCase(PolygonTestCase)