22
22
HAS_ARROW_WRITE_API ,
23
23
HAS_PYPROJ ,
24
24
PANDAS_GE_15 ,
25
+ SHAPELY_GE_21 ,
25
26
)
26
27
from pyogrio .errors import DataLayerError , DataSourceError , FeatureError , GeometryError
27
28
from pyogrio .geopandas import PANDAS_GE_20 , read_dataframe , write_dataframe
@@ -1803,23 +1804,29 @@ def test_write_geometry_z_types_auto(
1803
1804
1804
1805
1805
1806
@pytest .mark .parametrize (
1806
- "on_invalid, message" ,
1807
+ "on_invalid, message, expected_wkt " ,
1807
1808
[
1808
1809
(
1809
1810
"warn" ,
1810
1811
"Invalid WKB: geometry is returned as None. IllegalArgumentException: "
1811
- "Invalid number of points in LinearRing found 2 - must be 0 or >=" ,
1812
+ "Points of LinearRing do not form a closed linestring" ,
1813
+ None ,
1812
1814
),
1813
- ("raise" , "Invalid number of points in LinearRing found 2 - must be 0 or >=" ),
1814
- ("ignore" , None ),
1815
+ ("raise" , "Points of LinearRing do not form a closed linestring" , None ),
1816
+ ("ignore" , None , None ),
1817
+ ("fix" , None , "POLYGON ((0 0, 0 1, 0 0))" ),
1815
1818
],
1816
1819
)
1817
- def test_read_invalid_poly_ring (tmp_path , use_arrow , on_invalid , message ):
1820
+ @pytest .mark .filterwarnings ("ignore:Non closed ring detected:RuntimeWarning" )
1821
+ def test_read_invalid_poly_ring (tmp_path , use_arrow , on_invalid , message , expected_wkt ):
1822
+ if on_invalid == "fix" and not SHAPELY_GE_21 :
1823
+ pytest .skip ("on_invalid=fix not available for Shapely < 2.1" )
1824
+
1818
1825
if on_invalid == "raise" :
1819
1826
handler = pytest .raises (shapely .errors .GEOSException , match = message )
1820
1827
elif on_invalid == "warn" :
1821
1828
handler = pytest .warns (match = message )
1822
- elif on_invalid == " ignore" :
1829
+ elif on_invalid in ( "fix" , " ignore") :
1823
1830
handler = contextlib .nullcontext ()
1824
1831
else :
1825
1832
raise ValueError (f"unknown value for on_invalid: { on_invalid } " )
@@ -1833,7 +1840,7 @@ def test_read_invalid_poly_ring(tmp_path, use_arrow, on_invalid, message):
1833
1840
"properties": {},
1834
1841
"geometry": {
1835
1842
"type": "Polygon",
1836
- "coordinates": [ [ [0, 0], [0, 0 ] ] ]
1843
+ "coordinates": [ [ [0, 0], [0, 1 ] ] ]
1837
1844
}
1838
1845
}
1839
1846
]
@@ -1849,7 +1856,10 @@ def test_read_invalid_poly_ring(tmp_path, use_arrow, on_invalid, message):
1849
1856
use_arrow = use_arrow ,
1850
1857
on_invalid = on_invalid ,
1851
1858
)
1852
- df .geometry .isnull ().all ()
1859
+ if expected_wkt is None :
1860
+ assert df .geometry .iloc [0 ] is None
1861
+ else :
1862
+ assert df .geometry .iloc [0 ].wkt == expected_wkt
1853
1863
1854
1864
1855
1865
def test_read_multisurface (multisurface_file , use_arrow ):
0 commit comments