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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fix decode error reading an sqlite file on windows (#568).
- Fix wrong layername when creating .gpkg.zip file (#570).
- Fix segfault on providing an invalid value for `layer` in `read_info` (#564).
- Fix overwriting a corrupt fileGDB directory (#600).
- Fix error when reading data with ``use_arrow=True`` after having used the
Parquet driver with GDAL>=3.12 (#601).

Expand Down
11 changes: 10 additions & 1 deletion pyogrio/_io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import locale
import logging
import math
import os
import shutil
import sys
import warnings
from pathlib import Path
Expand Down Expand Up @@ -2391,7 +2392,15 @@ cdef create_ogr_dataset_layer(
raise exc

# otherwise create from scratch
os.unlink(path)
if (
driver == "OpenFileGDB"
and os.path.isdir(path)
and os.path.splitext(path)[1] == ".gdb"
):
# An FileGDB "file" is a directory instead of a file, so use rmtree
shutil.rmtree(path)
else:
os.unlink(path)

ogr_dataset = NULL

Expand Down
27 changes: 27 additions & 0 deletions pyogrio/tests/test_geopandas_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,33 @@ def test_write_geojson_rfc7946_coordinates(tmp_path, use_arrow):
assert np.array_equal(gdf_in_appended.geometry.values, points + points_append)


@pytest.mark.requires_arrow_write_api
def test_write_openfilegdb_overwrite_corrupt(tmp_path, use_arrow):
"""Test to overwriting an existing corrupt OpenFileGDB.

Test added in context of https://github.com/geopandas/pyogrio/issues/598
"""
# Create a corrupt OpenFileGDB file. An empty directory suffices.
test_path = tmp_path / "test.gdb"
test_path.mkdir()

# Overwrite the corrupt OpenFileGDB
gdf = gp.GeoDataFrame(
{"id": [1.0, 2.0, 3.0]},
geometry=[shapely.Point(x, x) for x in range(3)],
crs="EPSG:4326",
)
write_dataframe(
gdf, test_path, layer="test_layer", driver="OpenFileGDB", use_arrow=use_arrow
)

# Read back and verify it was (over)written correctly
assert test_path.exists()
assert test_path.is_dir()
read_gdf = read_dataframe(test_path, use_arrow=use_arrow)
assert_geodataframe_equal(gdf, read_gdf)


@pytest.mark.requires_arrow_api
@pytest.mark.skipif(
not GDAL_HAS_PARQUET_DRIVER, reason="Parquet driver is not available"
Expand Down
Loading