diff --git a/pyogrio/_compat.py b/pyogrio/_compat.py index cd67247e..fc3df94d 100644 --- a/pyogrio/_compat.py +++ b/pyogrio/_compat.py @@ -8,6 +8,11 @@ except ImportError: pyarrow = None +try: + import pyproj +except ImportError: + pyproj = None + try: import shapely except ImportError: @@ -27,6 +32,7 @@ HAS_ARROW_API = __gdal_version__ >= (3, 6, 0) HAS_ARROW_WRITE_API = __gdal_version__ >= (3, 8, 0) HAS_PYARROW = pyarrow is not None +HAS_PYPROJ = pyproj is not None HAS_GEOPANDAS = geopandas is not None diff --git a/pyogrio/tests/conftest.py b/pyogrio/tests/conftest.py index d562a4d1..85508464 100644 --- a/pyogrio/tests/conftest.py +++ b/pyogrio/tests/conftest.py @@ -14,6 +14,7 @@ HAS_ARROW_WRITE_API, HAS_GDAL_GEOS, HAS_PYARROW, + HAS_PYPROJ, HAS_SHAPELY, ) from pyogrio.raw import read, write @@ -54,6 +55,8 @@ def pytest_report_header(config): not HAS_ARROW_API or not HAS_PYARROW, reason="GDAL>=3.6 and pyarrow required" ) +requires_pyproj = pytest.mark.skipif(not HAS_PYPROJ, reason="pyproj required") + requires_arrow_write_api = pytest.mark.skipif( not HAS_ARROW_WRITE_API or not HAS_PYARROW, reason="GDAL>=3.8 required for Arrow write API", diff --git a/pyogrio/tests/test_geopandas_io.py b/pyogrio/tests/test_geopandas_io.py index 12146c3d..7786afb1 100644 --- a/pyogrio/tests/test_geopandas_io.py +++ b/pyogrio/tests/test_geopandas_io.py @@ -20,9 +20,10 @@ DRIVERS, requires_pyarrow_api, requires_arrow_write_api, + requires_pyproj, requires_gdal_geos, ) -from pyogrio._compat import PANDAS_GE_15, HAS_ARROW_WRITE_API +from pyogrio._compat import HAS_PYPROJ, PANDAS_GE_15, HAS_ARROW_WRITE_API try: import pandas as pd @@ -126,7 +127,8 @@ def test_read_csv_platform_encoding(tmp_path): def test_read_dataframe(naturalearth_lowres_all_ext): df = read_dataframe(naturalearth_lowres_all_ext) - assert df.crs == "EPSG:4326" + if HAS_PYPROJ: + assert df.crs == "EPSG:4326" assert len(df) == 177 assert df.columns.tolist() == [ "pop_est", @@ -1071,6 +1073,8 @@ def test_write_empty_geometry(tmp_path): # Check that no warning is raised with GeoSeries.notna() with warnings.catch_warnings(): warnings.simplefilter("error", UserWarning) + if not HAS_PYPROJ: + warnings.filterwarnings("ignore", message="'crs' was not provided.") write_dataframe(expected, filename) assert filename.exists() @@ -1460,6 +1464,7 @@ def test_write_dataframe_infer_geometry_with_nulls(tmp_path, geoms, ext, use_arr "ignore: You will likely lose important projection information" ) @pytest.mark.requires_arrow_write_api +@requires_pyproj def test_custom_crs_io(tmp_path, naturalearth_lowres_all_ext, use_arrow): df = read_dataframe(naturalearth_lowres_all_ext) # project Belgium to a custom Albers Equal Area projection