forked from rerun-io/rerun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rerun_py: Improvements to dataframe and simple unit-test framework (r…
…erun-io#7600) ### What - Allow `select()` to support `*args` - Return a `RecordBatchReader` instead of `list[RecordBatch]` - Add a unit-test that creates a recording, opens it, and does some stuff. We still aren't able to iterate over the result-set without collecting it, as we need to fix: https://github.com/rerun-io/rerun/blob/b5aa6e95b68e931d981af52abb706422f46bdfa7/crates/store/re_dataframe2/src/engine.rs#L31-L34 Future work: - Lots of fun stuff to do here with the zoo
- Loading branch information
Showing
4 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from __future__ import annotations | ||
|
||
import tempfile | ||
|
||
import pyarrow as pa | ||
import rerun as rr | ||
|
||
|
||
class TestDataframe: | ||
def setup_method(self) -> None: | ||
rr.init("rerun_example_test_recording") | ||
|
||
rr.log("points", rr.Points3D([[1, 2, 3], [4, 5, 6], [7, 8, 9]])) | ||
rr.log("points", rr.Points3D([[10, 11, 12]], colors=[[255, 0, 0]])) | ||
|
||
with tempfile.TemporaryDirectory() as tmpdir: | ||
rrd = tmpdir + "/tmp.rrd" | ||
|
||
rr.save(rrd) | ||
|
||
self.recording = rr.dataframe.load_recording(rrd) | ||
|
||
def test_full_view(self) -> None: | ||
view = self.recording.view(index="log_time", contents="points") | ||
|
||
batches = view.select() | ||
table = pa.Table.from_batches(batches, batches.schema) | ||
|
||
# row, log_time, log_tick, indicator, points, colors | ||
assert table.num_columns == 6 | ||
assert table.num_rows == 2 | ||
|
||
def test_select_column(self) -> None: | ||
view = self.recording.view(index="log_time", contents="points") | ||
pos = rr.dataframe.ComponentColumnSelector("points", rr.components.Position3D) | ||
batches = view.select(pos) | ||
|
||
table = pa.Table.from_batches(batches, batches.schema) | ||
# points | ||
assert table.num_columns == 1 | ||
assert table.num_rows == 2 | ||
|
||
expected0 = pa.array( | ||
[ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9], | ||
], | ||
type=rr.components.Position3D.arrow_type(), | ||
) | ||
|
||
expected1 = pa.array( | ||
[ | ||
[10, 11, 12], | ||
], | ||
type=rr.components.Position3D.arrow_type(), | ||
) | ||
|
||
assert table.column(0)[0].values.equals(expected0) | ||
assert table.column(0)[1].values.equals(expected1) | ||
|
||
def test_view_syntax(self) -> None: | ||
good_content_expressions = [ | ||
{"points": rr.components.Position3D}, | ||
{"points": [rr.components.Position3D]}, | ||
{"points": "rerun.components.Position3D"}, | ||
{"points/**": "rerun.components.Position3D"}, | ||
] | ||
|
||
for expr in good_content_expressions: | ||
view = self.recording.view(index="log_time", contents=expr) | ||
batches = view.select() | ||
table = pa.Table.from_batches(batches, batches.schema) | ||
|
||
# row, log_time, log_tick, points | ||
assert table.num_columns == 4 | ||
assert table.num_rows == 2 | ||
|
||
bad_content_expressions = [ | ||
{"points": rr.components.Position2D}, | ||
{"point": [rr.components.Position3D]}, | ||
] | ||
|
||
for expr in bad_content_expressions: | ||
view = self.recording.view(index="log_time", contents=expr) | ||
batches = view.select() | ||
|
||
# row, log_time, log_tick | ||
table = pa.Table.from_batches(batches, batches.schema) | ||
assert table.num_columns == 3 | ||
assert table.num_rows == 0 |