@@ -259,7 +259,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs):
259259 try :
260260 grp = _create_group (_store , path = path , overwrite = True , zarr_version = zarr_version )
261261 for i , arr in enumerate (args ):
262- k = "arr_{}" . format ( i )
262+ k = f "arr_{ i } "
263263 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
264264 for k , arr in kwargs .items ():
265265 grp .create_dataset (k , data = arr , overwrite = True , zarr_version = zarr_version )
@@ -499,7 +499,7 @@ def __init__(self, log):
499499 self .log_file = log
500500 else :
501501 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 } "
503503 )
504504
505505 def __enter__ (self ):
@@ -526,9 +526,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied):
526526 message = "dry run: "
527527 else :
528528 message = "all done: "
529- message += "{ :,} copied, {:,} skipped". format ( n_copied , n_skipped )
529+ message += f" { n_copied :,} copied, { n_skipped :,} skipped"
530530 if not dry_run :
531- message += ", {:,} bytes copied" . format ( n_bytes_copied )
531+ message += f ", { n_bytes_copied :,} bytes copied"
532532 log (message )
533533
534534
@@ -657,9 +657,7 @@ def copy_store(
657657 # check if_exists parameter
658658 valid_if_exists = ["raise" , "replace" , "skip" ]
659659 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} " )
663661
664662 # setup counting variables
665663 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 (
@@ -910,11 +908,9 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
910908 # check if_exists parameter
911909 valid_if_exists = ["raise" , "replace" , "skip" , "skip_initialized" ]
912910 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} " )
916912 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" )
918914
919915 # determine name to copy to
920916 if name is None :
@@ -934,9 +930,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
934930 exists = dest is not None and name in dest
935931 if exists :
936932 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} " )
940934 elif if_exists == "skip" :
941935 do_copy = False
942936 elif if_exists == "skip_initialized" :
@@ -947,7 +941,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
947941 # take action
948942 if do_copy :
949943 # 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 } " )
951945
952946 if not dry_run :
953947 # clear the way
@@ -1015,7 +1009,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10151009 n_copied += 1
10161010
10171011 else :
1018- log ("skip {} {} {}" . format ( source .name , source .shape , source .dtype ) )
1012+ log (f "skip { source .name } { source .shape } { source .dtype } " )
10191013 n_skipped += 1
10201014
10211015 elif root or not shallow :
@@ -1026,16 +1020,14 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10261020 exists_array = dest is not None and name in dest and hasattr (dest [name ], "shape" )
10271021 if exists_array :
10281022 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} " )
10321024 elif if_exists == "skip" :
10331025 do_copy = False
10341026
10351027 # take action
10361028 if do_copy :
10371029 # log action
1038- log ("copy {}" . format ( source .name ) )
1030+ log (f "copy { source .name } " )
10391031
10401032 if not dry_run :
10411033 # clear the way
@@ -1078,7 +1070,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
10781070 n_copied += 1
10791071
10801072 else :
1081- log ("skip {}" . format ( source .name ) )
1073+ log (f "skip { source .name } " )
10821074 n_skipped += 1
10831075
10841076 return n_copied , n_skipped , n_bytes_copied
@@ -1327,7 +1319,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
13271319 store , storage_options = kwargs .get ("storage_options" ), mode = mode , zarr_version = zarr_version
13281320 )
13291321 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} " )
13311323
13321324 path = kwargs .pop ("path" , None )
13331325 if store ._store_version == 2 :
0 commit comments