@@ -259,7 +259,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
259
259
try :
260
260
grp = _create_group (_store , path = path , overwrite = True , zarr_version = zarr_version )
261
261
for i , arr in enumerate (args ):
262
- k = "arr_{}" . format ( i )
262
+ k = f "arr_{ i } "
263
263
grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
264
264
for k , arr in kwargs .items ():
265
265
grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
@@ -499,7 +499,7 @@ def __init__(self, log):
499
499
self .log_file = log
500
500
else :
501
501
raise TypeError (
502
- "log must be a callable function, file path or " " file-like object, found %r" % log
502
+ f "log must be a callable function, file path or file-like object, found { log !r } "
503
503
)
504
504
505
505
def __enter__ (self ):
@@ -526,9 +526,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied):
526
526
message = "dry run: "
527
527
else :
528
528
message = "all done: "
529
- message += "{ :,} copied, {:,} skipped". format ( n_copied , n_skipped )
529
+ message += f" { n_copied :,} copied, { n_skipped :,} skipped"
530
530
if not dry_run :
531
- message += ", {:,} bytes copied" . format ( n_bytes_copied )
531
+ message += f ", { n_bytes_copied :,} bytes copied"
532
532
log (message )
533
533
534
534
@@ -657,9 +657,7 @@ def copy_store(
657
657
# check if_exists parameter
658
658
valid_if_exists = ["raise" , "replace" , "skip" ]
659
659
if if_exists not in valid_if_exists :
660
- raise ValueError (
661
- "if_exists must be one of {!r}; found {!r}" .format (valid_if_exists , if_exists )
662
- )
660
+ raise ValueError (f"if_exists must be one of { valid_if_exists !r} ; found { if_exists !r} " )
663
661
664
662
# setup counting variables
665
663
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 (
@@ -910,11 +908,9 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
910
908
# check if_exists parameter
911
909
valid_if_exists = ["raise" , "replace" , "skip" , "skip_initialized" ]
912
910
if if_exists not in valid_if_exists :
913
- raise ValueError (
914
- "if_exists must be one of {!r}; found {!r}" .format (valid_if_exists , if_exists )
915
- )
911
+ raise ValueError (f"if_exists must be one of { valid_if_exists !r} ; found { if_exists !r} " )
916
912
if dest_h5py and if_exists == "skip_initialized" :
917
- raise ValueError ("{ !r} can only be used when copying to zarr". format ( if_exists ) )
913
+ raise ValueError (f" { if_exists !r} can only be used when copying to zarr" )
918
914
919
915
# determine name to copy to
920
916
if name is None :
@@ -934,9 +930,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
934
930
exists = dest is not None and name in dest
935
931
if exists :
936
932
if if_exists == "raise" :
937
- raise CopyError (
938
- "an object {!r} already exists in destination " "{!r}" .format (name , dest .name )
939
- )
933
+ raise CopyError (f"an object { name !r} already exists in destination { dest .name !r} " )
940
934
elif if_exists == "skip" :
941
935
do_copy = False
942
936
elif if_exists == "skip_initialized" :
@@ -947,7 +941,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
947
941
# take action
948
942
if do_copy :
949
943
# log a message about what we're going to do
950
- log ("copy {} {} {}" . format ( source .name , source .shape , source .dtype ) )
944
+ log (f "copy { source .name } { source .shape } { source .dtype } " )
951
945
952
946
if not dry_run :
953
947
# clear the way
@@ -1015,7 +1009,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1015
1009
n_copied += 1
1016
1010
1017
1011
else :
1018
- log ("skip {} {} {}" . format ( source .name , source .shape , source .dtype ) )
1012
+ log (f "skip { source .name } { source .shape } { source .dtype } " )
1019
1013
n_skipped += 1
1020
1014
1021
1015
elif root or not shallow :
@@ -1026,16 +1020,14 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1026
1020
exists_array = dest is not None and name in dest and hasattr (dest [name ], "shape" )
1027
1021
if exists_array :
1028
1022
if if_exists == "raise" :
1029
- raise CopyError (
1030
- "an array {!r} already exists in destination " "{!r}" .format (name , dest .name )
1031
- )
1023
+ raise CopyError (f"an array { name !r} already exists in destination { dest .name !r} " )
1032
1024
elif if_exists == "skip" :
1033
1025
do_copy = False
1034
1026
1035
1027
# take action
1036
1028
if do_copy :
1037
1029
# log action
1038
- log ("copy {}" . format ( source .name ) )
1030
+ log (f "copy { source .name } " )
1039
1031
1040
1032
if not dry_run :
1041
1033
# clear the way
@@ -1078,7 +1070,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
1078
1070
n_copied += 1
1079
1071
1080
1072
else :
1081
- log ("skip {}" . format ( source .name ) )
1073
+ log (f "skip { source .name } " )
1082
1074
n_skipped += 1
1083
1075
1084
1076
return n_copied , n_skipped , n_bytes_copied
@@ -1327,7 +1319,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
1327
1319
store , storage_options = kwargs .get ("storage_options" ), mode = mode , zarr_version = zarr_version
1328
1320
)
1329
1321
if mode not in {"r" , "r+" }:
1330
- raise ValueError ("invalid mode, expected either 'r' or 'r+'; found {!r}" . format ( mode ) )
1322
+ raise ValueError (f "invalid mode, expected either 'r' or 'r+'; found { mode !r} " )
1331
1323
1332
1324
path = kwargs .pop ("path" , None )
1333
1325
if store ._store_version == 2 :
0 commit comments