@@ -258,7 +258,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
258258 try :
259259 grp = _create_group (_store , path = path , overwrite = True , zarr_version = zarr_version )
260260 for i , arr in enumerate (args ):
261- k = "arr_{}" . format ( i )
261+ k = f "arr_{ i } "
262262 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
263263 for k , arr in kwargs .items ():
264264 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
@@ -498,7 +498,7 @@ def __init__(self, log):
498498 self .log_file = log
499499 else :
500500 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 } "
502502 )
503503
504504 def __enter__ (self ):
@@ -525,9 +525,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied):
525525 message = "dry run: "
526526 else :
527527 message = "all done: "
528- message += "{ :,} copied, {:,} skipped". format ( n_copied , n_skipped )
528+ message += f" { n_copied :,} copied, { n_skipped :,} skipped"
529529 if not dry_run :
530- message += ", {:,} bytes copied" . format ( n_bytes_copied )
530+ message += f ", { n_bytes_copied :,} bytes copied"
531531 log (message )
532532
533533
@@ -656,9 +656,7 @@ def copy_store(
656656 # check if_exists parameter
657657 valid_if_exists = ["raise" , "replace" , "skip" ]
658658 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} " )
662660
663661 # setup counting variables
664662 n_copied = n_skipped = n_bytes_copied = 0
@@ -721,20 +719,20 @@ def copy_store(
721719 if if_exists != "replace" :
722720 if dest_key in dest :
723721 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" )
725723 elif if_exists == "skip" :
726724 do_copy = False
727725
728726 # take action
729727 if do_copy :
730- log ("copy {}" . format ( descr ) )
728+ log (f "copy { descr } " )
731729 if not dry_run :
732730 data = source [source_key ]
733731 n_bytes_copied += buffer_size (data )
734732 dest [dest_key ] = data
735733 n_copied += 1
736734 else :
737- log ("skip {}" . format ( descr ) )
735+ log (f "skip { descr } " )
738736 n_skipped += 1
739737
740738 # log a final message with a summary of what happened
@@ -745,7 +743,7 @@ def copy_store(
745743
746744def _check_dest_is_group (dest ):
747745 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} " )
749747
750748
751749def copy (
@@ -757,7 +755,7 @@ def copy(
757755 log = None ,
758756 if_exists = "raise" ,
759757 dry_run = False ,
760- ** create_kws
758+ ** create_kws ,
761759):
762760 """Copy the `source` array or group into the `dest` group.
763761
@@ -890,7 +888,7 @@ def copy(
890888 without_attrs = without_attrs ,
891889 if_exists = if_exists ,
892890 dry_run = dry_run ,
893- ** create_kws
891+ ** create_kws ,
894892 )
895893
896894 # 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_
912910 # check if_exists parameter
913911 valid_if_exists = ["raise" , "replace" , "skip" , "skip_initialized" ]
914912 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} " )
918914 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" )
920916
921917 # determine name to copy to
922918 if name is None :
@@ -936,9 +932,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
936932 exists = dest is not None and name in dest
937933 if exists :
938934 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} " )
942936 elif if_exists == "skip" :
943937 do_copy = False
944938 elif if_exists == "skip_initialized" :
@@ -950,7 +944,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
950944 if do_copy :
951945
952946 # 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 } " )
954948
955949 if not dry_run :
956950
@@ -1019,7 +1013,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10191013 n_copied += 1
10201014
10211015 else :
1022- log ("skip {} {} {}" . format ( source .name , source .shape , source .dtype ) )
1016+ log (f "skip { source .name } { source .shape } { source .dtype } " )
10231017 n_skipped += 1
10241018
10251019 elif root or not shallow :
@@ -1030,17 +1024,15 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10301024 exists_array = dest is not None and name in dest and hasattr (dest [name ], "shape" )
10311025 if exists_array :
10321026 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} " )
10361028 elif if_exists == "skip" :
10371029 do_copy = False
10381030
10391031 # take action
10401032 if do_copy :
10411033
10421034 # log action
1043- log ("copy {}" . format ( source .name ) )
1035+ log (f "copy { source .name } " )
10441036
10451037 if not dry_run :
10461038
@@ -1076,7 +1068,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10761068 without_attrs = without_attrs ,
10771069 if_exists = if_exists ,
10781070 dry_run = dry_run ,
1079- ** create_kws
1071+ ** create_kws ,
10801072 )
10811073 n_copied += c
10821074 n_skipped += s
@@ -1085,7 +1077,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10851077 n_copied += 1
10861078
10871079 else :
1088- log ("skip {}" . format ( source .name ) )
1080+ log (f "skip { source .name } " )
10891081 n_skipped += 1
10901082
10911083 return n_copied , n_skipped , n_bytes_copied
@@ -1099,7 +1091,7 @@ def copy_all(
10991091 log = None ,
11001092 if_exists = "raise" ,
11011093 dry_run = False ,
1102- ** create_kws
1094+ ** create_kws ,
11031095):
11041096 """Copy all children of the `source` group into the `dest` group.
11051097
@@ -1201,7 +1193,7 @@ def copy_all(
12011193 without_attrs = without_attrs ,
12021194 if_exists = if_exists ,
12031195 dry_run = dry_run ,
1204- ** create_kws
1196+ ** create_kws ,
12051197 )
12061198 n_copied += c
12071199 n_skipped += s
@@ -1336,7 +1328,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
13361328 store , storage_options = kwargs .get ("storage_options" ), mode = mode , zarr_version = zarr_version
13371329 )
13381330 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} " )
13401332
13411333 path = kwargs .pop ("path" , None )
13421334 if store ._store_version == 2 :
0 commit comments