8000 CLN: more conversions to f-string · larray-project/larray@70bd84b · GitHub
[go: up one dir, main page]

Skip to content

Commit 70bd84b

Browse files
committed
CLN: more conversions to f-string
1 parent 4d155ec commit 70bd84b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

larray/core/axis.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,7 @@ def align(self, other, join='outer'):
13721372
return other
13731373
elif join == 'exact':
13741374
if not self.equals(other):
1375-
raise ValueError("align method with join='exact' "
1376-
"expected {!r} to be equal to {!r}".format(self, other))
1375+
raise ValueError(f"align method with join='exact' expected {self!r} to be equal to {other!r}")
13771376
else:
13781377
return self
13791378

@@ -1537,7 +1536,7 @@ def __init__(self, axes=None):
15371536
# axis_dupes = list(duplicates(axis.labels))
15381537
# if axis_dupes:
15391538
# dupe_labels = ', '.join(str(l) for l in axis_dupes)
1540-
# warnings.warn("duplicate labels found for axis %s: %s" % (axis.name, dupe_labels),
1539+
# warnings.warn(f"duplicate labels found for axis {axis.name}: {dupe_labels}",
15411540
# category=UserWarning, stacklevel=2)
15421541
#
15431542
# # check dupes between axes. Using unique to not spot the dupes within the same axis that we just displayed.
@@ -1547,8 +1546,8 @@ def __init__(self, axes=None):
15471546
# label_axes = [(label, ', '.join(display_name for axis, display_name in zip(axes, self.display_names)
15481547
# if label in axis))
15491548
# for label in dupe_labels]
1550-
# dupes = '\n'.join("{} is valid in {{{}}}".format(label, axes) for label, axes in label_axes)
1551-
# warnings.warn("ambiguous labels found:\n%s" % dupes, category=UserWarning, stacklevel=5)
1549+
# dupes = '\n'.join(f"{label} is valid in {{{axes}}}" for label, axes in label_axes)
1550+
# warnings.warn(f"ambiguous labels found:\n{dupes}", category=UserWarning, stacklevel=5)
15521551

15531552
def __dir__(self):
15541553
# called by dir() and tab-completion at the interactive prompt, must return a list of any valid getattr key.
@@ -2857,7 +2856,7 @@ def _translated_key(self, key):
28572856
dupe_axes = list(duplicates(axis for axis, axis_key in key_items))
28582857
if dupe_axes:
28592858
dupe_axes = ', '.join(str(axis) for axis in dupe_axes)
2860-
raise ValueError("key has several values for axis: %s\n%s" % (dupe_axes, key_items))
2859+
raise ValueError(f"key has several values for axis: {dupe_axes}\n{key_items}")
28612860

28622861
# IGroup -> raw positional
28632862
dict_key = {axis: axis.index(axis_key) for axis, axis_key in key_items}

larray/extra/ipfp.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,18 @@ def has_anonymous_axes(a):
268268
stepcelldiff = abs(r - startr).max()
269269

270270
if display_progress:
271+
maxcelldiff = f2str(stepcelldiff)
272+
maxdiff2target = f2str(max_sum_diff)
273+
stepchange = f2str(step_sum_improvement)
271274
if display_progress == "condensed":
272-
template = "it {} max cell diff {} max diff to target {} ({})"
275+
print(f"it {i} max cell diff {maxcelldiff} max diff to target {maxdiff2target} "
276+
f"({stepchange})")
273277
else:
274-
template = """iteration {}
275-
* max(abs(prev_cell - cell)): {}
276-
* max(abs(sum - target_sum)): {}
277-
\\- change since last iteration: {}
278-
"""
279-
print(template.format(i, f2str(stepcelldiff), f2str(max_sum_diff), f2str(step_sum_improvement)))
278+
print(f"""iteration {i}
279+
* max(abs(prev_cell - cell)): {maxcelldiff}
280+
* max(abs(sum - target_sum)): {maxdiff2target}
281+
\\- change since last iteration: {stepchange}
282+
""")
280283

281284
if np.all(np.array(lastdiffs) == max_sum_diff):
282285
if no_convergence in {'warn', 'raise'}:

0 commit comments

Comments
 (0)
0