-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change occurrences of % and format() to f-strings #1423
Merged
joshmoore
merged 3 commits into
zarr-developers:main
from
DimitriPapadopoulos:f-strings
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,7 +259,7 @@ def save_group(store: StoreLike, *args, zarr_version=None, path=None, **kwargs): | |
try: | ||
grp = _create_group(_store, path=path, overwrite=True, zarr_version=zarr_version) | ||
for i, arr in enumerate(args): | ||
k = "arr_{}".format(i) | ||
k = f"arr_{i}" | ||
grp.create_dataset(k, data=arr, overwrite=True, zarr_version=zarr_version) | ||
for k, arr in kwargs.items(): | ||
grp.create_dataset(k, data=arr, overwrite=True, zarr_version=zarr_version) | ||
|
@@ -499,7 +499,7 @@ def __init__(self, log): | |
self.log_file = log | ||
else: | ||
raise TypeError( | ||
"log must be a callable function, file path or " "file-like object, found %r" % log | ||
f"log must be a callable function, file path or file-like object, found {log!r}" | ||
) | ||
|
||
def __enter__(self): | ||
|
@@ -526,9 +526,9 @@ def _log_copy_summary(log, dry_run, n_copied, n_skipped, n_bytes_copied): | |
message = "dry run: " | ||
else: | ||
message = "all done: " | ||
message += "{:,} copied, {:,} skipped".format(n_copied, n_skipped) | ||
message += f"{n_copied:,} copied, {n_skipped:,} skipped" | ||
if not dry_run: | ||
message += ", {:,} bytes copied".format(n_bytes_copied) | ||
message += f", {n_bytes_copied:,} bytes copied" | ||
log(message) | ||
|
||
|
||
|
@@ -657,9 +657,7 @@ def copy_store( | |
# check if_exists parameter | ||
valid_if_exists = ["raise", "replace", "skip"] | ||
if if_exists not in valid_if_exists: | ||
raise ValueError( | ||
"if_exists must be one of {!r}; found {!r}".format(valid_if_exists, if_exists) | ||
) | ||
raise ValueError(f"if_exists must be one of {valid_if_exists!r}; found {if_exists!r}") | ||
|
||
# setup counting variables | ||
n_copied = n_skipped = n_bytes_copied = 0 | ||
|
@@ -720,20 +718,20 @@ def copy_store( | |
if if_exists != "replace": | ||
if dest_key in dest: | ||
if if_exists == "raise": | ||
raise CopyError("key {!r} exists in destination".format(dest_key)) | ||
raise CopyError(f"key {dest_key!r} exists in destination") | ||
elif if_exists == "skip": | ||
do_copy = False | ||
|
||
# take action | ||
if do_copy: | ||
log("copy {}".format(descr)) | ||
log(f"copy {descr}") | ||
if not dry_run: | ||
data = source[source_key] | ||
n_bytes_copied += buffer_size(data) | ||
dest[dest_key] = data | ||
n_copied += 1 | ||
else: | ||
log("skip {}".format(descr)) | ||
log(f"skip {descr}") | ||
n_skipped += 1 | ||
|
||
# log a final message with a summary of what happened | ||
|
@@ -744,7 +742,7 @@ def copy_store( | |
|
||
def _check_dest_is_group(dest): | ||
if not hasattr(dest, "create_dataset"): | ||
raise ValueError("dest must be a group, got {!r}".format(dest)) | ||
raise ValueError(f"dest must be a group, got {dest!r}") | ||
|
||
|
||
def copy( | ||
|
@@ -910,11 +908,9 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
# check if_exists parameter | ||
valid_if_exists = ["raise", "replace", "skip", "skip_initialized"] | ||
if if_exists not in valid_if_exists: | ||
raise ValueError( | ||
"if_exists must be one of {!r}; found {!r}".format(valid_if_exists, if_exists) | ||
) | ||
raise ValueError(f"if_exists must be one of {valid_if_exists!r}; found {if_exists!r}") | ||
if dest_h5py and if_exists == "skip_initialized": | ||
raise ValueError("{!r} can only be used when copying to zarr".format(if_exists)) | ||
raise ValueError(f"{if_exists!r} can only be used when copying to zarr") | ||
|
||
# determine name to copy to | ||
if name is None: | ||
|
@@ -934,9 +930,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
exists = dest is not None and name in dest | ||
if exists: | ||
if if_exists == "raise": | ||
raise CopyError( | ||
"an object {!r} already exists in destination " "{!r}".format(name, dest.name) | ||
) | ||
raise CopyError(f"an object {name!r} already exists in destination {dest.name!r}") | ||
elif if_exists == "skip": | ||
do_copy = False | ||
elif if_exists == "skip_initialized": | ||
|
@@ -947,7 +941,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
# take action | ||
if do_copy: | ||
# log a message about what we're going to do | ||
log("copy {} {} {}".format(source.name, source.shape, source.dtype)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
See also: |
||
log(f"copy {source.name} {source.shape} {source.dtype}") | ||
|
||
if not dry_run: | ||
# clear the way | ||
|
@@ -1015,7 +1009,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
n_copied += 1 | ||
|
||
else: | ||
log("skip {} {} {}".format(source.name, source.shape, source.dtype)) | ||
log(f"skip {source.name} {source.shape} {source.dtype}") | ||
n_skipped += 1 | ||
|
||
elif root or not shallow: | ||
|
@@ -1026,16 +1020,14 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
exists_array = dest is not None and name in dest and hasattr(dest[name], "shape") | ||
if exists_array: | ||
if if_exists == "raise": | ||
raise CopyError( | ||
"an array {!r} already exists in destination " "{!r}".format(name, dest.name) | ||
) | ||
raise CopyError(f"an array {name!r} already exists in destination {dest.name!r}") | ||
elif if_exists == "skip": | ||
do_copy = False | ||
|
||
# take action | ||
if do_copy: | ||
# log action | ||
log("copy {}".format(source.name)) | ||
log(f"copy {source.name}") | ||
|
||
if not dry_run: | ||
# clear the way | ||
|
@@ -1078,7 +1070,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_ | |
n_copied += 1 | ||
|
||
else: | ||
log("skip {}".format(source.name)) | ||
log(f"skip {source.name}") | ||
n_skipped += 1 | ||
|
||
return n_copied, n_skipped, n_bytes_copied | ||
|
@@ -1327,7 +1319,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", ** | |
store, storage_options=kwargs.get("storage_options"), mode=mode, zarr_version=zarr_version | ||
) | ||
if mode not in {"r", "r+"}: | ||
raise ValueError("invalid mode, expected either 'r' or 'r+'; found {!r}".format(mode)) | ||
raise ValueError(f"invalid mode, expected either 'r' or 'r+'; found {mode!r}") | ||
|
||
path = kwargs.pop("path", None) | ||
if store._store_version == 2: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string was cut in half, looks like a left-over from #1459.