Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOErrors to OSErrors #725

Merged
merged 1 commit into from
Aug 28, 2023
Merged
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
14 changes: 7 additions & 7 deletions eolearn/core/eodata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _infer_temporal_selection(

patch_timestamps = eopatch.get_timestamps("Cannot infer temporal selection. EOPatch to be saved has no timestamps.")
if file_information.timestamps is None:
raise IOError("Cannot infer temporal selection. Saved EOPatch does not have timestamps.")
raise OSError("Cannot infer temporal selection. Saved EOPatch does not have timestamps.")
full_timestamps = FeatureIOTimestamps(file_information.timestamps, filesystem).load()
timestamp_indices = {timestamp: idx for idx, timestamp in enumerate(full_timestamps)}
if not all(timestamp in timestamp_indices for timestamp in patch_timestamps):
Expand Down Expand Up @@ -332,7 +332,7 @@ def _extract_temporal_selection(
full_timestamps = FeatureIOTimestamps(timestamps_path, filesystem).load()
simple_selection = temporal_selection(full_timestamps)
return simple_selection, [timestamp for timestamp, include in zip(full_timestamps, simple_selection) if include]
raise IOError(f"Cannot perform loading temporal selection, EOPatch at {patch_location} has no timestamps.")
raise OSError(f"Cannot perform loading temporal selection, EOPatch at {patch_location} has no timestamps.")


def _load_features(
Expand Down Expand Up @@ -361,7 +361,7 @@ def _load_features(
features_dict[(ftype, fname)] = _get_feature_io(ftype, path, filesystem, temporal_selection)
else:
if ftype not in file_information.features or fname not in file_information.features[ftype]:
raise IOError(err_msg.format((ftype, fname)))
raise OSError(err_msg.format((ftype, fname)))
path = file_information.features[ftype][fname]
features_dict[(ftype, fname)] = _get_feature_io(ftype, path, filesystem, temporal_selection)
return features_dict
Expand All @@ -382,7 +382,7 @@ def _get_feature_io(
return FeatureIOZarr(path, filesystem, temporal_selection)
if temporal_selection is None:
return FeatureIONumpy(path, filesystem)
raise IOError(
raise OSError(
f"Cannot perform loading with temporal selection for numpy data at {path}. Resave feature with"
" `use_zarr=True` to enable loading with temporal selections."
)
Expand Down Expand Up @@ -470,11 +470,11 @@ def _check_letter_case_collisions(eopatch_features: Features, filesystem_feature
lowercase_features = {_to_lowercase(*feature) for feature in eopatch_features}

if len(lowercase_features) != len(eopatch_features):
raise IOError("Some features differ only in casing and cannot be saved in separate files.")
raise OSError("Some features differ only in casing and cannot be saved in separate files.")

for feature, _ in filesystem_features.iterate_features():
if feature not in eopatch_features and _to_lowercase(*feature) in lowercase_features:
raise IOError(
raise OSError(
f"There already exists a feature {feature} in the filesystem that only differs in "
"casing from a feature that should be saved."
)
Expand Down Expand Up @@ -775,7 +775,7 @@ def save(
zarr_shape = (full_size, *data.shape[1:])
zarray = zarr.create(zarr_shape, dtype=data.dtype, chunks=chunk_size, store=store)
else:
raise IOError(
raise OSError(
f"Unable to open Zarr array at {path!r}. Saving with `temporal_selection` requires an initialized"
' zarr array. You can also try saving with `temporal_selection="infer"`.'
) from error
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ ignore = [
"B904", # want `raise ... from None` instead of just `raise ...`
"B028", # always demands a stacklevel argument when warning
"PT011", # complains for `pytest.raises(ValueError)` but we use it a lot
"UP024", # wants to switch IOError with OSError
]
per-file-ignores = { "__init__.py" = ["F401", "I002"], "conf.py" = ["I002", "FA100"] }
exclude = [".git", "__pycache__", "build", "dist"]
Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_eodata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_overwrite_failure(fs_loader, use_zarr: bool):
eopatch.mask_timeless["mask"] = mask
eopatch.mask_timeless["Mask"] = mask

with fs_loader() as temp_fs, pytest.raises(IOError):
with fs_loader() as temp_fs, pytest.raises(OSError):
eopatch.save("/", filesystem=temp_fs, use_zarr=use_zarr)

with fs_loader() as temp_fs:
Expand All @@ -298,7 +298,7 @@ def test_overwrite_failure(fs_loader, use_zarr: bool):
use_zarr=use_zarr,
)

with pytest.raises(IOError):
with pytest.raises(OSError):
eopatch.save(
"/",
filesystem=temp_fs,
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_fail_saving_nonexistent_feature(eopatch, fs_loader):
@pytest.mark.parametrize("fs_loader", FS_LOADERS)
def test_fail_loading_nonexistent_feature(fs_loader):
for features in [[(FeatureType.DATA, "nonexistent")], [(FeatureType.META_INFO, "nonexistent")]]:
with fs_loader() as temp_fs, pytest.raises(IOError):
with fs_loader() as temp_fs, pytest.raises(OSError):
EOPatch.load("/", filesystem=temp_fs, features=features)


Expand Down Expand Up @@ -593,7 +593,7 @@ def test_partial_temporal_loading_fails_for_numpy(fs_loader: type[FS], eopatch:
with fs_loader() as temp_fs:
eopatch.save(path="patch-folder", filesystem=temp_fs, use_zarr=False)

with pytest.raises(IOError):
with pytest.raises(OSError):
EOPatch.load(path="patch-folder", filesystem=temp_fs, temporal_selection=[0])


Expand Down Expand Up @@ -683,7 +683,7 @@ def test_partial_temporal_saving_fails(eopatch: EOPatch):
io_kwargs = dict(
path="patch-folder", filesystem=temp_fs, use_zarr=True, overwrite_permission="OVERWRITE_FEATURES"
)
with pytest.raises(IOError):
with pytest.raises(OSError):
# patch does not exist yet
eopatch.save(**io_kwargs, temporal_selection=slice(2, None))

Expand All @@ -710,7 +710,7 @@ def test_partial_temporal_saving_fails(eopatch: EOPatch):
EOPatch(bbox=eopatch.bbox, timestamps=["2012-01-01"]).save(**io_kwargs, temporal_selection="infer")

EOPatch(bbox=eopatch.bbox).save(path="other-folder", filesystem=temp_fs)
with pytest.raises(IOError, match=r"Saved EOPatch does not have timestamps"):
with pytest.raises(OSError, match=r"Saved EOPatch does not have timestamps"):
# no timestamps saved
eopatch.save(path="other-folder", filesystem=temp_fs, use_zarr=True, temporal_selection="infer")

Expand Down