зеркало из https://github.com/microsoft/torchgeo.git
GeoDataset: allow a mix of str and pathlib paths (#2270)
* GeoDataset: allow a mix of str and pathlib paths * Update type hints * Simpler str conversion
This commit is contained in:
Родитель
da6ff04a77
Коммит
6576b40019
|
@ -205,6 +205,14 @@ class TestGeoDataset:
|
||||||
CustomGeoDataset(paths=paths1).files == CustomGeoDataset(paths=paths2).files
|
CustomGeoDataset(paths=paths1).files == CustomGeoDataset(paths=paths2).files
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_files_property_mix_str_and_pathlib(self, tmp_path: Path) -> None:
|
||||||
|
foo = tmp_path / 'foo.txt'
|
||||||
|
bar = tmp_path / 'bar.txt'
|
||||||
|
foo.touch()
|
||||||
|
bar.touch()
|
||||||
|
ds = CustomGeoDataset(paths=[str(foo), bar])
|
||||||
|
assert ds.files == [str(bar), str(foo)]
|
||||||
|
|
||||||
|
|
||||||
class TestRasterDataset:
|
class TestRasterDataset:
|
||||||
naip_dir = os.path.join('tests', 'data', 'naip')
|
naip_dir = os.path.join('tests', 'data', 'naip')
|
||||||
|
|
|
@ -291,7 +291,7 @@ class GeoDataset(Dataset[dict[str, Any]], abc.ABC):
|
||||||
self._res = new_res
|
self._res = new_res
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def files(self) -> list[Path]:
|
def files(self) -> list[str]:
|
||||||
"""A list of all files in the dataset.
|
"""A list of all files in the dataset.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -306,7 +306,7 @@ class GeoDataset(Dataset[dict[str, Any]], abc.ABC):
|
||||||
paths = self.paths
|
paths = self.paths
|
||||||
|
|
||||||
# Using set to remove any duplicates if directories are overlapping
|
# Using set to remove any duplicates if directories are overlapping
|
||||||
files: set[Path] = set()
|
files: set[str] = set()
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
pathname = os.path.join(path, '**', self.filename_glob)
|
pathname = os.path.join(path, '**', self.filename_glob)
|
||||||
|
@ -314,7 +314,7 @@ class GeoDataset(Dataset[dict[str, Any]], abc.ABC):
|
||||||
elif (os.path.isfile(path) or path_is_vsi(path)) and fnmatch.fnmatch(
|
elif (os.path.isfile(path) or path_is_vsi(path)) and fnmatch.fnmatch(
|
||||||
str(path), f'*{self.filename_glob}'
|
str(path), f'*{self.filename_glob}'
|
||||||
):
|
):
|
||||||
files.add(path)
|
files.add(str(path))
|
||||||
elif not hasattr(self, 'download'):
|
elif not hasattr(self, 'download'):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Could not find any relevant files for provided path '{path}'. "
|
f"Could not find any relevant files for provided path '{path}'. "
|
||||||
|
|
Загрузка…
Ссылка в новой задаче