Repository navigation
fix(dynamictable): add an empty ragged row without advancing the index - #908
Conversation
addRow treated a value without elements as a single element. On a column that has an index, the index advanced by one although nothing was added, so every later row pointed at the wrong elements. On a column without an index, nothing was added at all while the id grew. Give an empty value the nesting depth of a ragged row, so the column gets an index when it has none, and let the data level report that no element was added. getTypeMap skips a column that has no element to take the type from, which a table has after an empty first row. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #908 +/- ##
==========================================
+ Coverage 95.29% 95.30% +0.01%
==========================================
Files 239 239
Lines 8795 8804 +9
==========================================
+ Hits 8381 8391 +10
+ Misses 414 413 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
The depth variable here refers to how many vectors are needed to describe a column.
depth = 1 - Only VectorData - standard column
depth = 2 - VectorData + VectorIndex - ragged column
depth = n - VectorData + (n-1) VectorIndex - nested ragged column
There was a problem hiding this comment.
This function is used to find the data type of a column based on the columns first row. It is used when adding rows, to validate that the newly added row values match the type that already exists in each column.
If a column has no data elements yet, it is considered "untyped"
Motivation
Fixes a bug where
addRowsilently writes a wrong index when a ragged row has no elements: rows of 3, 0 and 2 elements give[3 4 6]instead of[3 3 5].Background — A ragged column has a different number of elements in each row. All the elements are stored in one dataset, and an index holds the position where each row ends. Rows of 3, 0 and 2 elements give the index
[3 3 5]: the empty row ends where the row before it ends.Problem —
addRowwrites a wrong index when a row has no elements, for example a unit without spikes. Adding rows of 3, 0 and 2 spike times gives the index[3 4 6]instead of[3 3 5].addRowcounts the empty value as one element, so the index moves forward by one although nothing is added to the data. Every later row then points one element too far: the empty row reads back with 1 element, and the last row points past the end of the data. Nothing reports it when the rows are added and the export succeeds. The error only appears when a row is read.Solution —
addRowreads a value without elements as a row with zero elements. The index repeats its previous value for that row, and the rows after it are read correctly.This is one of several independent fixes for DynamicTable helper bugs found in an audit of
+types/+util/+dynamictable. #895 fixes otheraddRowerrors for ragged columns and does not cover this case.What changed
addRowwith[], or with{}for a text column, adds an empty row to a ragged column.addRowfailed, because the table had an id without a matching row in the column.addRowfailed.Implementation notes
In
addRawData.m,getNestedDataDepthgives a value without elements the nesting depth of a ragged row, so the column gets an index when it has none and the value is no longer wrapped as a single element.nestedAddreports zero added elements for an empty value at the data level without touching the data.getTypeMapskips a column that has no element to take the type from, which is the state of a table after an empty first row.On a doubly ragged column,
[]adds a row with one empty sub-row.Examples
Empty row between two rows
Three units are added with 3, 0 and 2 spike times, and each row is read back.
Before — The index is silently wrong. The column holds the 5 spike times, but the index ends at 6. The second row reads back with 1 element, which is the first spike of the third unit, and the third row fails.
After — The index repeats 3 for the empty row and ends at 5, the number of spike times. Each row reads back with the number of elements it was given.
Empty row as the first row
The first unit has no spike times, and the second has 2.
Before — The first
addRowadds an id but no row to the column, so the secondaddRowfails. The last line shows the one id that was added.After — The first row ends at element 0 and the second at element 2. The table has two ids.
How to test
Run the new tests:
Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code