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:
+11
-5
@@ -1975,11 +1975,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:
|
||||
|
||||
Reference in New Issue
Block a user