Skip to content
Open
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
4 changes: 4 additions & 0 deletions pyogrio/_io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ cdef OGRLayerH get_ogr_layer(GDALDatasetH ogr_dataset, layer) except NULL:

elif isinstance(layer, int):
ogr_layer = check_pointer(GDALDatasetGetLayer(ogr_dataset, layer))
else:
raise ValueError(
f"'layer' parameter must be a str or int, got {type(layer)}"
)

# GDAL does not always raise exception messages in this case
except NullPointerError:
Expand Down
4 changes: 2 additions & 2 deletions pyogrio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def read_info(
----------
path_or_buffer : str, pathlib.Path, bytes, or file-like
A dataset path or URI, raw buffer, or file-like object with a read method.
layer : [type], optional
layer : str or int, optional
Name or index of layer in data source. Reads the first layer by default.
encoding : [type], optional (default: None)
encoding : str, optional (default: None)
If present, will be used as the encoding for reading string values from
the data source, unless encoding can be inferred directly from the data
source.
Expand Down
5 changes: 5 additions & 0 deletions pyogrio/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ def test_read_info_unspecified_layer_warning(data_dir):
read_info(data_dir / "sample.osm.pbf")


def test_read_info_invalid_layer(naturalearth_lowres):
with pytest.raises(ValueError, match="'layer' parameter must be a str or int"):
read_bounds(naturalearth_lowres, layer=["list_arg_is_invalid"])


def test_read_info_without_geometry(no_geometry_file):
assert read_info(no_geometry_file)["total_bounds"] is None

Expand Down
Loading