massung / tabular-asa

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

is `table-groupby` guaranteed to be stable? #10

Open jbclements opened 4 days ago

jbclements commented 4 days ago

I'm wondering if the rows in the tables generated by table-groupby always appear in the order in which they occurred in the original table? I'm guessing the answer is yes, and I'd love to nail this down by adding a few tests and some documentation for this.

massung commented 3 days ago

It's been a while since I wrote this, but the applicable code is in table-groupby.

I think there are a couple things to note and consider:

The groups are collected and sorted by their index (see: group-indices). This little snippet does two things:

So, the default behavior is to return each group - and the rows inside that group - to be exactly the same as they were in the source table.

However, it's also possible to supply a less-than? sorting parameter to the function, which will sort the final list of keys generated and return each table in sorted-key order. But the order of the rows within that table should still be in original-table order.

Definitely not opposed to more tests and documentation, though. 😄