From 6fe4edcaefa93cb29cda99488c3ed07051d0c3c2 Mon Sep 17 00:00:00 2001 From: Liam Rahimian <74251943+Liam-hi@users.noreply.github.com> Date: Sat, 22 Apr 2023 00:45:08 +0200 Subject: [PATCH] Improve code readability and performance by using f-strings Using f-strings can improve both the readability and performance. - F-strings make it easier to embed variables directly in the string, resulting in more concise and easier-to-read code. - F-strings are often faster than concatenation because they are evaluated at runtime rather than being built up piece by piece. --- .../projects/timelines/scripts/models/earlybird/metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/twitter/deepbird/projects/timelines/scripts/models/earlybird/metrics.py b/src/python/twitter/deepbird/projects/timelines/scripts/models/earlybird/metrics.py index 6919914f8..e6e6840f5 100644 --- a/src/python/twitter/deepbird/projects/timelines/scripts/models/earlybird/metrics.py +++ b/src/python/twitter/deepbird/projects/timelines/scripts/models/earlybird/metrics.py @@ -71,7 +71,7 @@ def get_multi_binary_class_metric_fn(metrics, classes=None, class_dim=1): for metric_name in metrics: metric_name = metric_name.lower() # metric name are case insensitive. - class_metric_name = metric_name + "_" + (classes[i] if classes is not None else str(i)) + class_metric_name = f"{metric_name}_{classes[i] if classes is not None else i}" if class_metric_name in eval_metric_ops: # avoid adding duplicate metrics.