jtablesaw / tablesaw

Java dataframe and visualization library
https://jtablesaw.github.io/tablesaw/
Apache License 2.0
3.56k stars 645 forks source link

Index out of bounds exception when setting values on a Row #1184

Open uzzell opened 1 year ago

uzzell commented 1 year ago

When I create a Row from a Table (without specifying a row number) and try to set a value on the Row, I get an error.

Steps to reproduce:

Column<?> col = DoubleColumn.create("column", 1);
Table table = Table.create(col);
Row row = new Row(table);
row.setDouble("column", 0);

Actual result: This produces java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 128. No wonder: the Row's rowNumber equals -1, so it's trying to set the -1th entry of the column.

If I use a (valid) row index to create the Row, as in Row row = new Row(table, 0), everything is fine.

Expected result: No exception

uzzell commented 1 year ago

Now that I've thought about this for a bit, it looks like this behavior reflects the fact that a Row object represents both a set of data (i.e., a row of a Relation) and an Iterator over sets of data. When one uses this constructor, the object returned acts like a newly instantiated Iterator. However--and this is the reason for the surprise--it does not act like a row of a Relation. One must iterate before any data is exposed.

lwhite1 commented 1 year ago

Yes, it’s really an integrator as creating rows would be very expensive

On Mon, Feb 13, 2023 at 11:22 AM uzzell @.***> wrote:

Now that I've thought about this for a bit, it looks like this behavior reflects the fact that a Row object represents both a set of data (i.e., a row of a Relation) and an Iterator over sets of data. When one uses this constructor, the object returned acts like a newly instantiated Iterator. However--and this is the reason for the surprise--it does not act like a row of a Relation. One must iterate before any data is exposed.

— Reply to this email directly, view it on GitHub https://github.com/jtablesaw/tablesaw/issues/1184#issuecomment-1428235514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2FPAUTNB4CQI3Y5G2ISODWXJNVNANCNFSM6AAAAAAUVUR2WY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

uzzell commented 1 year ago

It would be helpful if the documentation for this constructor indicated that the Row object created wasn't positioned at any index of the Table.