Skip to content

Commit

Permalink
Fix some tests when pyproj not available
Browse files Browse the repository at this point in the history
  • Loading branch information
theroggy committed Jul 27, 2024
1 parent e7abe19 commit eb4b6d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pyogrio/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
except ImportError:
pyarrow = None

try:
import pyproj
except ImportError:
pyproj = None

try:
import shapely
except ImportError:
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions pyogrio/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
HAS_ARROW_WRITE_API,
HAS_GDAL_GEOS,
HAS_PYARROW,
HAS_PYPROJ,
HAS_SHAPELY,
)
from pyogrio.raw import read, write
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb4b6d2

Please sign in to comment.