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