Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-rasterstats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies = [

[project.optional-dependencies]
progress = ["tqdm"]
fiona = ["fiona"]
fiona = ["fiona; python_version < '3.14'"]
docs = ["numpydoc", "sphinx", "sphinx-rtd-theme"]
test = [
"coverage",
Expand Down
12 changes: 2 additions & 10 deletions src/rasterstats/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@


def _fiona_generator(obj, layer=0):
"""Yield GeoJSON-like Feature dicts using fiona (optional engine).
"""Yield GeoJSON-like Feature dicts using fiona (optional engine)."""
import fiona

Raises ImportError with a helpful message if fiona is not installed.
"""
try:
import fiona
except ImportError:
raise ImportError(
"fiona is required for engine='fiona'. "
"Install it with: pip install rasterstats[fiona]"
)
try:
import fiona.model

Expand Down
27 changes: 24 additions & 3 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from shapely.geometry import shape

from rasterstats.io import ( # todo parse_feature
DEFAULT_CHUNK_SIZE,
Raster,
_is_vector_file,
boundless_array,
Expand Down Expand Up @@ -537,7 +536,7 @@ def test_geodataframe():


def test_feature_generator_chunk_size(tmp_path):
"""Reading with default engine, fiona engine, and alternative chunk sizes
"""Reading with default engine vs alternative chunk sizes,
all result in equivalent feature dicts."""
geojson = {
"type": "FeatureCollection",
Expand All @@ -555,9 +554,31 @@ def test_feature_generator_chunk_size(tmp_path):

default_results = list(feature_generator(polygons))
small_chunk_results = list(feature_generator(polygons, chunk_size=2))
fiona_results = list(feature_generator(polygons, engine="fiona", chunk_size=2))

assert default_results == small_chunk_results


def test_feature_generator_engines(tmp_path):
"""Reading with default engine vs fiona engine,
all result in equivalent feature dicts."""
_ = pytest.importorskip("fiona")
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [float(i), 0.0]},
"properties": {"n": i},
}
for i in range(6)
],
}
p = tmp_path / "chunked.geojson"
p.write_text(json.dumps(geojson))

default_results = list(feature_generator(polygons))
fiona_results = list(feature_generator(polygons, engine="fiona", chunk_size=2))

# cannot compare them directly since they differ in tuples vs list representation for some reason
# let json roundtrip normalize it
assert json.loads(json.dumps(default_results)) == json.loads(
Expand Down
Loading