Skip to content

Commit 52da3ec

Browse files
committed
pr feedback
1 parent 408b278 commit 52da3ec

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

webknossos/webknossos/dataset/layer.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def add_mag_as_copy(
873873
self._ensure_writable()
874874
foreign_mag_view = MagView._ensure_mag_view(foreign_mag_view_or_path)
875875

876-
if (
876+
has_same_shapes = (
877877
(
878878
chunk_shape is None
879879
or Vec3Int.from_vec_or_int(chunk_shape)
@@ -889,19 +889,18 @@ def add_mag_as_copy(
889889
or Vec3Int.from_vec_or_int(chunks_per_shard)
890890
== foreign_mag_view.info.chunks_per_shard
891891
)
892-
and (self.data_format == foreign_mag_view.info.data_format)
893-
and (
894-
compress is None
895-
or (
896-
(
897-
not isinstance(compress, Zarr3Config)
898-
or not isinstance(foreign_mag_view.info, Zarr3ArrayInfo)
899-
or compress == foreign_mag_view.info.zarr3_config
900-
)
901-
and compress == foreign_mag_view.info.compression_mode
902-
)
903-
)
892+
)
893+
has_same_format = self.data_format == foreign_mag_view.info.data_format
894+
if compress is None:
895+
has_same_compression = True
896+
elif isinstance(compress, Zarr3Config) and isinstance(
897+
foreign_mag_view.info, Zarr3ArrayInfo
904898
):
899+
has_same_compression = compress == foreign_mag_view.info.zarr3_config
900+
else:
901+
has_same_compression = compress == foreign_mag_view.info.compression_mode
902+
903+
if has_same_shapes and has_same_format and has_same_compression:
905904
logger.debug(
906905
f"Optimization: Copying files from {foreign_mag_view.path} to {self.path}/{foreign_mag_view.mag} directly without re-encoding."
907906
)
@@ -1088,12 +1087,15 @@ def _add_fs_copy_mag(
10881087
foreign_mag_view = MagView._ensure_mag_view(foreign_mag_view_or_path)
10891088
self._assert_mag_does_not_exist_yet(foreign_mag_view.mag)
10901089

1091-
assert foreign_mag_view.info.data_format == self.data_format
1090+
assert foreign_mag_view.info.data_format == self.data_format, (
1091+
f"Cannot use file-based copy, because the foreign data format {foreign_mag_view.info.data_format} does not match the layer's data format {self.data_format}."
1092+
)
10921093

10931094
mag_path = self.path / str(foreign_mag_view.mag)
1094-
assert exists_ok or not mag_path.exists(), (
1095-
f"Cannot copy {foreign_mag_view.path} to {mag_path} because it already exists and `exist_ok` is set to False."
1096-
)
1095+
if not exists_ok and mag_path.exists():
1096+
raise FileExistsError(
1097+
f"Cannot copy {foreign_mag_view.path} to {mag_path} because it already exists."
1098+
)
10971099
copytree(
10981100
foreign_mag_view.path,
10991101
mag_path,

0 commit comments

Comments
 (0)