crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] A zero-sum numeric column makes the last data row look like a total row

Open Luckyou-d opened this issue 2 weeks ago • 0 comments

Description

total_row decides that the last row of a sheet is a total when any numeric column's last value equals the sum of the column above it. A column that sums to zero satisfies that for free when its last value is also zero, because math.isclose(0.0, 0.0) is trivially true.

So an ordinary data row gets hidden from every aggregate as soon as one numeric column ends in zero and sums to zero:

item,amount     ->  describe: "2 rows (its total row, row 4, is left out)"
a,0
b,0
c,0
item,delta      ->  describe: "2 rows (its total row, row 4, is left out)"
a,5
b,-5
c,0

rows still returns the row, so the same sheet is 3 rows for one operation and 2 for another, and the last row silently disappears from describe, value_counts, group_by and the overview's column profile.

Expected behavior

A zero sum should not count as evidence that the last row is a total. Rows whose sum is not zero keep working exactly as before, so ["a", 1], ["b", 2], ["c", 3], ["Total", 6] and the unlabelled [None, 6] variant are still detected.

The remaining ambiguity - an ordinary labelled row that happens to add up, e.g. 1, 2, 3 - is inherent to the documented heuristic and is left alone here.

Environment

crewai-files on main (f4da03a), Python 3.13, Windows.

Reproduction

from crewai_files.spreadsheets.answers import Query, query
from crewai_files.spreadsheets.reading import parse

workbook = parse(b"item,amount
a,0
b,0
c,0
", "t.csv")
print(query(workbook, "t.csv", Query(operation="describe")).splitlines()[1])
# data: 2 rows (its total row, row 4, is left out).

A fix with regression tests is ready.

Luckyou-d avatar Nov 15 '26 10:11 Luckyou-d