From 4d8893fb0529cffd71a8c6561769ff97a0668e69 Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Mon, 6 Jan 2025 10:09:10 +0100 Subject: [PATCH] FIX: Manage case where we have a `pd.Dataframe` instead of a `gpd.GeoDataFrame` in `vectors.read` (reading a `.dbf` file for instance) --- CHANGES.md | 4 ++++ ci/test_vectors.py | 7 ++++++- sertit/vectors.py | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9201113..e06d41c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release History +## 1.44.3 (2025-mm-dd) + +- FIX: Manage case where we have a `pd.Dataframe` instead of a `gpd.GeoDataFrame` in `vectors.read` (reading a `.dbf` file for instance) + ## 1.44.2 (2024-12-23) - **ENH: Drop `isort`, `black` and `flake8` and use `ruff`** diff --git a/ci/test_vectors.py b/ci/test_vectors.py index 273077c..390103a 100644 --- a/ci/test_vectors.py +++ b/ci/test_vectors.py @@ -349,9 +349,14 @@ def test_read_gdb(): def test_read_dbf(): """Test read from GDB""" + # DataFrame DBF (just check it works) + dbf_path = vectors_path() / "a0_source.dbf" + vectors.read(dbf_path) + + # GeoDataFrame DBF dbf_path = vectors_path() / "aoi.dbf" - fiona = vectors.read(dbf_path) + fiona = vectors.read(dbf_path, engine="fiona") pyogrio = vectors.read(dbf_path, engine="pyogrio") ci.assert_geom_equal(fiona, pyogrio) diff --git a/sertit/vectors.py b/sertit/vectors.py index 15074e8..ef6ec54 100644 --- a/sertit/vectors.py +++ b/sertit/vectors.py @@ -19,6 +19,7 @@ You can use this only if you have installed sertit[full] or sertit[vectors] """ +import contextlib import logging import os import re @@ -514,8 +515,9 @@ def read( vect.attrs["name"] = path.get_filename(vector_path) # Generate spatial index for optimization - if kwargs.get("compute_sindex", True) and not vect.has_sindex: - vect.sindex # noqa + with contextlib.suppress(AttributeError): + if kwargs.get("compute_sindex", True) and not vect.has_sindex: + vect.sindex # noqa return vect