massung / tabular-asa

A column-oriented, dataframe implementation for Racket.
MIT License
17 stars 4 forks source link

repair a problem with adding columns to dataframes with no rows #7

Open jbclements opened 4 months ago

jbclements commented 4 months ago

The existing code appears to have a bug that prevents adding a column to a table with columns but no rows. Specifically, it uses argmax on the index vector to determine the size of the new vector, but for tables with columns but no rows, this index vector is empty, and argmax signals an error. To solve this, I special-case the empty vector and return zero as the length of the new vector.

jbclements commented 4 months ago

Sorry, I should add: I also added a test that no longer fails.

massung commented 4 months ago

@jbclements - thanks for this. I'll look it over. Regardless, nice find. Gotta love edge cases. :wink:

massung commented 3 months ago

I've fixed this differently in caf938a. I've added a table-index-size function (unexposed right now) and bumped the version.

Thanks again!

massung commented 3 months ago

Ah... correct. The fix is good, just the test is wrong.

(test-case "Add column to table with columns and no rows"
           (let ([zero-rows-table (table-with-column empty-table '() #:as 'a)])
             (check-table (table-with-column zero-rows-table '(1 2 3) #:as 'b)
                          '(a b)
                          '())))

Would you agree this test reflects the fix?