scripts: Relaxed lost results due to unstable by fields to a warning

So it turns out this _can_ happen, without an in-script coding error.

Consider the behavior of a script with overlapping by/field fields:

  $ cat test.csv
  a,b
  x,2
  x,1
  x,1
  $ ./scripts/csv.py test.csv -ba -bb -fb

During the first fold, rows 2 and 3 will contain b=1, but during the
second fold they will have been merged, resulting in b=2.

So, relaxing to a warning for now. Maybe the table renderer should be
rewritten to avoid folding? (note diffing results may be tricky)
This commit is contained in:
Christopher Haster
2026-02-01 12:47:05 -06:00
parent b1d8114889
commit a3082437df
9 changed files with 99 additions and 45 deletions
+11 -5
View File
@@ -801,11 +801,17 @@ def table(Result, results, diff_results=None, *,
for k in by): r
for r in diff_results or []}
# lost results? this only happens if we didn't fold by the same
# by field, which is an error and risks confusing results
assert len(table) == len(results)
if diff_results is not None:
assert len(diff_table) == len(diff_results)
# lost results? note this can happen if a by field references the
# same field as a field field, and the field field changes during
# folding
#
# it's not an _error_, but can lead to really confusing results, so
# at least warn
if (len(table) != len(results)
or (diff_results is not None
and len(diff_table) != len(diff_results))):
print("warning: by fields are unstable",
file=sys.stderr)
# find compare entry if there is one
if compare: