scripts: csv.py: Ignore missing by fields in enumerate/accumulate

Note this matches the behavior of mods, e.g. I would expect this to not
break if ORDER is missing:

  ./scripts/csv.py \
      -bcase='%(case)s+%(probe)s+%(ORDER)s' \
      -ft=accumulate(bench_simtime, case, probe, ORDER)

Normally the expr compiler would force typechecking of ORDER, giving it
a default value of int(0) if missing, but we intentionally bypass
typechecking in enumerate/accumulate's by fields since they may be
strings.
This commit is contained in:
Christopher Haster
2026-02-02 12:15:00 -06:00
parent 7e307f2160
commit 484b7dd1e8
+4 -12
View File
@@ -812,12 +812,8 @@ class CsvExpr:
return CsvInt(0)
# enumerate
k = ['enumerate', id(self)]
for v in self:
if v.a not in fields:
raise CsvExpr.Error("unknown field? %s" % v.a)
k.append(fields[v.a])
k = tuple(k)
k = ('enumerate', id(self)) + tuple(
fields.get(v.a) for v in self)
x = state.get(k)
if x is None:
x = 0
@@ -852,12 +848,8 @@ class CsvExpr:
return y
# accumulate
k = ['accumulate', id(self)]
for v in it.islice(self, 1, None):
if v.a not in fields:
raise CsvExpr.Error("unknown field? %s" % v.a)
k.append(fields[v.a])
k = tuple(k)
k = ('accumulate', id(self)) + tuple(
fields.get(v.a) for v in it.islice(self, 1, None))
x = state.get(k)
if x is None:
x = y