Skip to content

Commit 8d419be

Browse files
authored
BUG: fix read_file and to_file errors (geopandas#3628)
1 parent 523ce28 commit 8d419be

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Bug fixes:
66

77
- Fix an issue that caused an error in `GeoDataFrame.from_features` when there is no `properties` field (#3599).
8+
- Fix `read_file` and `to_file` errors (#3682)
89

910
## Version 1.1.1 (June 27, 2025)
1011

geopandas/io/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _check_pyogrio(func):
101101
raise ImportError(
102102
f"the {func} requires the 'pyogrio' package, but it is not installed "
103103
"or does not import correctly."
104-
"\nImporting pyogrio resulted in: {pyogrio_import_error}"
104+
f"\nImporting pyogrio resulted in: {pyogrio_import_error}"
105105
)
106106

107107

geopandas/io/tests/test_file.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,40 @@ def test_error_engine_unavailable_fiona(tmp_path, df_points, file_path):
15141514
df_points.to_file(tmp_path / "test.gpkg", engine="fiona")
15151515

15161516

1517+
def test_error_monkeypatch_engine_unavailable_pyogrio(
1518+
monkeypatch, tmp_path, df_points, file_path
1519+
) -> None:
1520+
# monkeypatch to make pyogrio unimportable
1521+
monkeypatch.setattr(geopandas.io.file, "_import_pyogrio", lambda: None)
1522+
monkeypatch.setattr(geopandas.io.file, "pyogrio", None)
1523+
monkeypatch.setattr(
1524+
geopandas.io.file, "pyogrio_import_error", "No module named 'pyogrio'"
1525+
)
1526+
1527+
with pytest.raises(ImportError, match="No module named 'pyogrio'"):
1528+
geopandas.read_file(file_path, engine="pyogrio")
1529+
1530+
with pytest.raises(ImportError, match="No module named 'pyogrio'"):
1531+
df_points.to_file(tmp_path / "test.gpkg", engine="pyogrio")
1532+
1533+
1534+
def test_error_monkeypatch_engine_unavailable_fiona(
1535+
monkeypatch, tmp_path, df_points, file_path
1536+
) -> None:
1537+
# monkeypatch to make fiona unimportable
1538+
monkeypatch.setattr(geopandas.io.file, "_import_fiona", lambda: None)
1539+
monkeypatch.setattr(geopandas.io.file, "fiona", None)
1540+
monkeypatch.setattr(
1541+
geopandas.io.file, "fiona_import_error", "No module named 'fiona'"
1542+
)
1543+
1544+
with pytest.raises(ImportError, match="No module named 'fiona'"):
1545+
geopandas.read_file(file_path, engine="fiona")
1546+
1547+
with pytest.raises(ImportError, match="No module named 'fiona'"):
1548+
df_points.to_file(tmp_path / "test.gpkg", engine="fiona")
1549+
1550+
15171551
@PYOGRIO_MARK
15181552
def test_list_layers(df_points, tmpdir):
15191553
tempfilename = os.path.join(str(tmpdir), "dataset.gpkg")

0 commit comments

Comments
 (0)