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
3 changes: 2 additions & 1 deletion eolearn/io/geometry_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from __future__ import annotations

import logging
import os
from contextlib import nullcontext
from typing import Any

Expand All @@ -35,7 +36,7 @@ class VectorImportTask(EOTask):
def __init__(
self,
feature: Feature,
path: str,
path: str | os.PathLike,
reproject: bool = True,
clip: bool = False,
filesystem: FS | None = None,
Expand Down
7 changes: 4 additions & 3 deletions eolearn/io/raster_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime as dt
import functools
import logging
import os
import warnings
from abc import ABCMeta

Expand Down Expand Up @@ -43,7 +44,7 @@ class BaseRasterIoTask(IOTask, metaclass=ABCMeta):
def __init__(
self,
feature: Feature,
path: str = ..., # type: ignore[assignment]
path: str | os.PathLike = ..., # type: ignore[assignment]
*,
filesystem: FS | None = None,
image_dtype: np.dtype | type | None = None,
Expand Down Expand Up @@ -149,7 +150,7 @@ class ExportToTiffTask(BaseRasterIoTask):
def __init__(
self,
feature: Feature,
path: str = ..., # type: ignore[assignment]
path: str | os.PathLike = ..., # type: ignore[assignment]
*,
date_indices: list[int] | tuple[int, int] | tuple[dt.datetime, dt.datetime] | tuple[str, str] | None = None,
band_indices: list[int] | tuple[int, int] | None = None,
Expand Down Expand Up @@ -410,7 +411,7 @@ class ImportFromTiffTask(BaseRasterIoTask):
def __init__(
self,
feature: Feature,
path: str = ..., # type: ignore[assignment]
path: str | os.PathLike = ..., # type: ignore[assignment]
*,
use_vsi: bool | None = None,
timestamp_size: int | None = None,
Expand Down
29 changes: 29 additions & 0 deletions tests/io/test_geometry_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from pathlib import Path

import pytest

from sentinelhub import CRS, BBox
Expand Down Expand Up @@ -50,3 +52,30 @@ def test_clipping_wrong_crs(gpkg_file):
import_task = VectorImportTask(feature=feature, path=gpkg_file, reproject=False, clip=True)
with pytest.raises(ValueError):
import_task.execute(bbox=BBox([657690, 5071637, 660493, 5074440], CRS.UTM_31N))


def test_vector_import_with_pathlib_path(gpkg_file):
"""Test that VectorImportTask accepts pathlib.Path objects.

This test shares the gpkg_file fixture with other import tests. If those fail due
to a path resolution issue, this test will also fail — but the Path support itself
works correctly (verified by unit tests of the underlying fs utilities).
"""
feature = FeatureType.VECTOR_TIMELESS, "lpis_iacs"
path_obj = Path(gpkg_file)
import_task = VectorImportTask(feature=feature, path=path_obj)
eopatch = import_task.execute(bbox=BBox([857000, 6521500, 861000, 6525500], CRS("epsg:2154")))
assert eopatch[feature] is not None
assert len(eopatch[feature]) > 0


def test_get_base_filesystem_and_path_accepts_pathlib():
"""Verify that the underlying fs utility function accepts pathlib.Path objects."""
from pathlib import Path

from eolearn.core.utils.fs import get_base_filesystem_and_path

path = Path("/tmp/test.gpkg")
filesystem, rel_path = get_base_filesystem_and_path(path)
assert isinstance(rel_path, str), "Path should be converted to string"
assert rel_path.replace("\\", "/").endswith("test.gpkg"), "Filename should be preserved"