From 616a02a87f3990034116c6d376faef1f8bb589b6 Mon Sep 17 00:00:00 2001 From: Jakob van Santen Date: Wed, 27 Nov 2024 17:23:38 +0100 Subject: [PATCH] ruff: avoid quadratic list summation --- ampel/ztf/view/ZTFT2Tabulator.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ampel/ztf/view/ZTFT2Tabulator.py b/ampel/ztf/view/ZTFT2Tabulator.py index abea711..b27b806 100644 --- a/ampel/ztf/view/ZTFT2Tabulator.py +++ b/ampel/ztf/view/ZTFT2Tabulator.py @@ -15,6 +15,7 @@ from ampel.abstract.AbsT2Tabulator import AbsT2Tabulator from ampel.content.DataPoint import DataPoint from ampel.types import StockId +from ampel.util.collections import ampel_iter from ampel.ztf.util.ZTFIdMapper import ZTFIdMapper ZTF_BANDPASSES = { @@ -89,17 +90,10 @@ def get_jd( def get_stock_id(self, dps: Iterable[DataPoint]) -> set[StockId]: return set( - sum( - [ - list(stockid) - if isinstance(stockid := el["stock"], Sequence) - and not isinstance(stockid, str | bytes) - else [stockid] - for el in dps - if "ZTF" in el["tag"] - ], - [], - ) + stockid + for el in dps + if "ZTF" in el["tag"] + for stockid in ampel_iter(el["stock"]) ) def get_stock_name(self, dps: Iterable[DataPoint]) -> list[str]: