@@ -258,7 +258,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
258
258
try :
259
259
grp = _create_group (_store , path = path , overwrite = True , zarr_version = zarr_version )
260
260
for i , arr in enumerate (args ):
261
- k = "arr_{}" . format ( i )
261
+ k = f "arr_{ i } "
262
262
grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
263
263
for k , arr in kwargs .items ():
264
264
grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
@@ -498,7 +498,7 @@ def __init__(self, log):
498
498
self .log_file = log
499
499
else :
500
500
raise TypeError (
501
- "log must be a callable function, file path or " " file-like object, found %r" % log
501
+ f "log must be a callable function, file path or file-like object, found { log !r } "
502
502
)
503
503
504
504
def __enter__ (self ):
@@ -525,9 +525,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied):
525
525
message = "dry run: "
526
526
else :
527
527
message = "all done: "
528
- message += "{ :,} copied, {:,} skipped". format ( n_copied , n_skipped )
528
+ message += f" { n_copied :,} copied, { n_skipped :,} skipped"
529
529
if not dry_run :
530
- message += ", {:,} bytes copied" . format ( n_bytes_copied )
530
+ message += f ", { n_bytes_copied :,} bytes copied"
531
531
log (message )
532
532
533
533
@@ -656,9 +656,7 @@ def copy_store(
656
656
# check if_exists parameter
657
657
valid_if_exists = ["raise" , "replace" , "skip" ]
658
658
if if_exists not in valid_if_exists :
659
- raise ValueError (
660
- "if_exists must be one of {!r}; found {!r}" .format (valid_if_exists , if_exists )
661
- )
659
+ raise ValueError (f"if_exists must be one of { valid_if_exists !r} ; found { if_exists !r} " )
662
660
663
661
# setup counting variables
664
662
n_copied = n_skipped = n_bytes_copied = 0
@@ -721,20 +719,20 @@ def copy_store(
721
719
if if_exists != "replace" :
722
720
if dest_key in dest :
723
721
if if_exists == "raise" :
724
- raise CopyError ("key {!r} exists in destination" . format ( dest_key ) )
722
+ raise CopyError (f "key { dest_key !r} exists in destination" )
725
723
elif if_exists == "skip" :
726
724
do_copy = False
727
725
728
726
# take action
729
727
if do_copy :
730
- log ("copy {}" . format ( descr ) )
728
+ log (f "copy { descr } " )
731
729
if not dry_run :
732
730
data = source [source_key ]
733
731
n_bytes_copied += buffer_size (data )
734
732
dest [dest_key ] = data
735
733
n_copied += 1
736
734
else :
737
- log ("skip {}" . format ( descr ) )
735
+ log (f "skip { descr } " )
738
736
n_skipped += 1
739
737
740
738
# log a final message with a summary of what happened
@@ -745,7 +743,7 @@ def copy_store(
745
743
746
744
def _check_dest_is_group (dest ):
747
745
if not hasattr (dest , "create_dataset" ):
748
- raise ValueError ("dest must be a group, got {!r}" . format ( dest ) )
746
+ raise ValueError (f "dest must be a group, got { dest !r} " )
749
747
750
748
751
749
def copy (
@@ -757,7 +755,7 @@ def copy(
757
755
log = None ,
758
756
if_exists = "raise" ,
759
757
dry_run = False ,
760
- ** create_kws
758
+ ** create_kws ,
761
759
):
762
760
"""Copy the `source` array or group into the `dest` group.
763
761
@@ -890,7 +888,7 @@ def copy(
890
888
without_attrs = without_attrs ,
891
889
if_exists = if_exists ,
892
890
dry_run = dry_run ,
893
- ** create_kws
891
+ ** create_kws ,
894
892
)
895
893
896
894
# log a final message with a summary of what happened
@@ -912,11 +910,9 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
912
910
# check if_exists parameter
913
911
valid_if_exists = ["raise" , "replace" , "skip" , "skip_initialized" ]
914
912
if if_exists not in valid_if_exists :
915
- raise ValueError (
916
- "if_exists must be one of {!r}; found {!r}" .format (valid_if_exists , if_exists )
917
- )
913
+ raise ValueError (f"if_exists must be one of { valid_if_exists !r} ; found { if_exists !r} " )
918
914
if dest_h5py and if_exists == "skip_initialized" :
919
- raise ValueError ("{ !r} can only be used when copying to zarr". format ( if_exists ) )
915
+ raise ValueError (f" { if_exists !r} can only be used when copying to zarr" )
920
916
921
917
# determine name to copy to
922
918
if name is None :
@@ -936,9 +932,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
936
932
exists = dest is not None and name in dest
937
933
if exists :
938
934
if if_exists == "raise" :
939
- raise CopyError (
940
- "an object {!r} already exists in destination " "{!r}" .format (name , dest .name )
941
- )
935
+ raise CopyError (f"an object { name !r} already exists in destination { dest .name !r} " )
942
936
elif if_exists == "skip" :
943
937
do_copy = False
944
938
elif if_exists == "skip_initialized" :
@@ -950,7 +944,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
950
944
if do_copy :
951
945
952
946
# log a message about what we're going to do
953
- log ("copy {} {} {}" . format ( source .name , source .shape , source .dtype ) )
947
+ log (f "copy { source .name } { source .shape } { source .dtype } " )
954
948
955
949
if not dry_run :
956
950
@@ -1019,7 +1013,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1019
1013
n_copied += 1
1020
1014
1021
1015
else :
1022
- log ("skip {} {} {}" . format ( source .name , source .shape , source .dtype ) )
1016
+ log (f "skip { source .name } { source .shape } { source .dtype } " )
1023
1017
n_skipped += 1
1024
1018
1025
1019
elif root or not shallow :
@@ -1030,17 +1024,15 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1030
1024
exists_array = dest is not None and name in dest and hasattr (dest [name ], "shape" )
1031
1025
if exists_array :
1032
1026
if if_exists == "raise" :
1033
- raise CopyError (
1034
- "an array {!r} already exists in destination " "{!r}" .format (name , dest .name )
1035
- )
1027
+ raise CopyError (f"an array { name !r} already exists in destination { dest .name !r} " )
1036
1028
elif if_exists == "skip" :
1037
1029
do_copy = False
1038
1030
1039
1031
# take action
1040
1032
if do_copy :
1041
1033
1042
1034
# log action
1043
- log ("copy {}" . format ( source .name ) )
1035
+ log (f "copy { source .name } " )
1044
1036
1045
1037
if not dry_run :
1046
1038
@@ -1076,7 +1068,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1076
1068
without_attrs = without_attrs ,
1077
1069
if_exists = if_exists ,
1078
1070
dry_run = dry_run ,
1079
- ** create_kws
1071
+ ** create_kws ,
1080
1072
)
1081
1073
n_copied += c
1082
1074
n_skipped += s
@@ -1085,7 +1077,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1085
1077
n_copied += 1
1086
1078
1087
1079
else :
1088
- log ("skip {}" . format ( source .name ) )
1080
+ log (f "skip { source .name } " )
1089
1081
n_skipped += 1
1090
1082
1091
1083
return n_copied , n_skipped , n_bytes_copied
@@ -1099,7 +1091,7 @@ def copy_all(
1099
1091
log = None ,
1100
1092
if_exists = "raise" ,
1101
1093
dry_run = False ,
1102
- ** create_kws
1094
+ ** create_kws ,
1103
1095
):
1104
1096
"""Copy all children of the `source` group into the `dest` group.
1105
1097
@@ -1201,7 +1193,7 @@ def copy_all(
1201
1193
without_attrs = without_attrs ,
1202
1194
if_exists = if_exists ,
1203
1195
dry_run = dry_run ,
1204
- ** create_kws
1196
+ ** create_kws ,
1205
1197
)
1206
1198
n_copied += c
1207
1199
n_skipped += s
@@ -1336,7 +1328,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
1336
1328
store , storage_options = kwargs .get ("storage_options" ), mode = mode , zarr_version = zarr_version
1337
1329
)
1338
1330
if mode not in {"r" , "r+" }:
1339
- raise ValueError ("invalid mode, expected either 'r' or 'r+'; found {!r}" . format ( mode ) )
1331
+ raise ValueError (f "invalid mode, expected either 'r' or 'r+'; found { mode !r} " )
1340
1332
1341
1333
path = kwargs .pop ("path" , None )
1342
1334
if store ._store_version == 2 :
0 commit comments