@@ -257,7 +257,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
257257 try :
258258 grp = _create_group (_store , path = path , overwrite = True , zarr_version = zarr_version )
259259 for i , arr in enumerate (args ):
260- k = "arr_{}" . format ( i )
260+ k = f "arr_{ i } "
261261 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
262262 for k , arr in kwargs .items ():
263263 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
@@ -497,7 +497,7 @@ def __init__(self, log):
497497 self .log_file = log
498498 else :
499499 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 } "
501501 )
502502
503503 def __enter__ (self ):
@@ -524,9 +524,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied):
524524 message = "dry run: "
525525 else :
526526 message = "all done: "
527- message += "{ :,} copied, {:,} skipped". format ( n_copied , n_skipped )
527+ message += f" { n_copied :,} copied, { n_skipped :,} skipped"
528528 if not dry_run :
529- message += ", {:,} bytes copied" . format ( n_bytes_copied )
529+ message += f ", { n_bytes_copied :,} bytes copied"
530530 log (message )
531531
532532
@@ -655,9 +655,7 @@ def copy_store(
655655 # check if_exists parameter
656656 valid_if_exists = ["raise" , "replace" , "skip" ]
657657 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} " )
661659
662660 # setup counting variables
663661 n_copied = n_skipped = n_bytes_copied = 0
@@ -720,20 +718,20 @@ def copy_store(
720718 if if_exists != "replace" :
721719 if dest_key in dest :
722720 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" )
724722 elif if_exists == "skip" :
725723 do_copy = False
726724
727725 # take action
728726 if do_copy :
729- log ("copy {}" . format ( descr ) )
727+ log (f "copy { descr } " )
730728 if not dry_run :
731729 data = source [source_key ]
732730 n_bytes_copied += buffer_size (data )
733731 dest [dest_key ] = data
734732 n_copied += 1
735733 else :
736- log ("skip {}" . format ( descr ) )
734+ log (f "skip { descr } " )
737735 n_skipped += 1
738736
739737 # log a final message with a summary of what happened
@@ -744,7 +742,7 @@ def copy_store(
744742
745743def _check_dest_is_group (dest ):
746744 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} " )
748746
749747
750748def copy (
@@ -756,7 +754,7 @@ def copy(
756754 log = None ,
757755 if_exists = "raise" ,
758756 dry_run = False ,
759- ** create_kws
757+ ** create_kws ,
760758):
761759 """Copy the `source` array or group into the `dest` group.
762760
@@ -889,7 +887,7 @@ def copy(
889887 without_attrs = without_attrs ,
890888 if_exists = if_exists ,
891889 dry_run = dry_run ,
892- ** create_kws
890+ ** create_kws ,
893891 )
894892
895893 # 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_
911909 # check if_exists parameter
912910 valid_if_exists = ["raise" , "replace" , "skip" , "skip_initialized" ]
913911 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} " )
917913 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" )
919915
920916 # determine name to copy to
921917 if name is None :
@@ -935,9 +931,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
935931 exists = dest is not None and name in dest
936932 if exists :
937933 if if_exists == "raise" :
938- raise CopyError (
939- "an object {!r} already exists in destination " "{!r}" .format (name , dest .name )
940- )
934+ raise CopyError (f"an object { name !r} already exists in destination { dest .name !r} " )
941935 elif if_exists == "skip" :
942936 do_copy = False
943937 elif if_exists == "skip_initialized" :
@@ -949,7 +943,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
949943 if do_copy :
950944
951945 # log a message about what we're going to do
952- log ("copy {} {} {}" . format ( source .name , source .shape , source .dtype ) )
946+ log (f "copy { source .name } { source .shape } { source .dtype } " )
953947
954948 if not dry_run :
955949
@@ -1018,7 +1012,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10181012 n_copied += 1
10191013
10201014 else :
1021- log ("skip {} {} {}" . format ( source .name , source .shape , source .dtype ) )
1015+ log (f "skip { source .name } { source .shape } { source .dtype } " )
10221016 n_skipped += 1
10231017
10241018 elif root or not shallow :
@@ -1029,17 +1023,15 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10291023 exists_array = dest is not None and name in dest and hasattr (dest [name ], "shape" )
10301024 if exists_array :
10311025 if if_exists == "raise" :
1032- raise CopyError (
1033- "an array {!r} already exists in destination " "{!r}" .format (name , dest .name )
1034- )
1026+ raise CopyError (f"an array { name !r} already exists in destination { dest .name !r} " )
10351027 elif if_exists == "skip" :
10361028 do_copy = False
10371029
10381030 # take action
10391031 if do_copy :
10401032
10411033 # log action
1042- log ("copy {}" . format ( source .name ) )
1034+ log (f "copy { source .name } " )
10431035
10441036 if not dry_run :
10451037
@@ -1075,7 +1067,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10751067 without_attrs = without_attrs ,
10761068 if_exists = if_exists ,
10771069 dry_run = dry_run ,
1078- ** create_kws
1070+ ** create_kws ,
10791071 )
10801072 n_copied += c
10811073 n_skipped += s
@@ -1084,7 +1076,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10841076 n_copied += 1
10851077
10861078 else :
1087- log ("skip {}" . format ( source .name ) )
1079+ log (f "skip { source .name } " )
10881080 n_skipped += 1
10891081
10901082 return n_copied , n_skipped , n_bytes_copied
@@ -1098,7 +1090,7 @@ def copy_all(
10981090 log = None ,
10991091 if_exists = "raise" ,
11001092 dry_run = False ,
1101- ** create_kws
1093+ ** create_kws ,
11021094):
11031095 """Copy all children of the `source` group into the `dest` group.
11041096
@@ -1200,7 +1192,7 @@ def copy_all(
12001192 without_attrs = without_attrs ,
12011193 if_exists = if_exists ,
12021194 dry_run = dry_run ,
1203- ** create_kws
1195+ ** create_kws ,
12041196 )
12051197 n_copied += c
12061198 n_skipped += s
@@ -1335,7 +1327,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
13351327 store , storage_options = kwargs .get ("storage_options" ), mode = mode , zarr_version = zarr_version
13361328 )
13371329 if mode not in {"r" , "r+" }:
1338- raise ValueError ("invalid mode, expected either 'r' or 'r+'; found {!r}" . format ( mode ) )
1330+ raise ValueError (f "invalid mode, expected either 'r' or 'r+'; found { mode !r} " )
13391331
13401332 path = kwargs .pop ("path" , None )
13411333 if store ._store_version == 2 :
0 commit comments