Skip to content

Commit

Permalink
Add Pathlib support to load_recording (rerun-io#7637)
Browse files Browse the repository at this point in the history
### What
- Resolves: rerun-io#7627

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7637?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7637?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/7637)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jleibs authored Oct 8, 2024
1 parent 5852681 commit 46e0b3b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
5 changes: 3 additions & 2 deletions rerun_py/rerun_bindings/rerun_bindings.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Optional, Sequence

import pyarrow as pa
Expand Down Expand Up @@ -70,7 +71,7 @@ class RRDArchive:
def num_recordings(self) -> int: ...
def all_recordings(self) -> list[Recording]: ...

def load_recording(filename: str) -> Recording:
def load_recording(filename: str | os.PathLike) -> Recording:
"""
Load a single recording from an RRD.
Expand All @@ -84,7 +85,7 @@ def load_recording(filename: str) -> Recording:
"""
...

def load_archive(filename: str) -> RRDArchive:
def load_archive(filename: str | os.PathLike) -> RRDArchive:
"""
Load a rerun archive file from disk.
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl PyRRDArchive {
}

#[pyfunction]
pub fn load_recording(path_to_rrd: String) -> PyResult<PyRecording> {
pub fn load_recording(path_to_rrd: std::path::PathBuf) -> PyResult<PyRecording> {
let archive = load_archive(path_to_rrd)?;

let num_recordings = archive.num_recordings();
Expand All @@ -624,7 +624,7 @@ pub fn load_recording(path_to_rrd: String) -> PyResult<PyRecording> {
}

#[pyfunction]
pub fn load_archive(path_to_rrd: String) -> PyResult<PyRRDArchive> {
pub fn load_archive(path_to_rrd: std::path::PathBuf) -> PyResult<PyRRDArchive> {
let stores =
ChunkStore::from_rrd_filepath(&ChunkStoreConfig::DEFAULT, path_to_rrd, VersionPolicy::Warn)
.map_err(|err| PyRuntimeError::new_err(err.to_string()))?;
Expand Down
33 changes: 33 additions & 0 deletions rerun_py/tests/unit/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
from __future__ import annotations

import pathlib
import tempfile

import pyarrow as pa
import rerun as rr


def test_load_recording() -> None:
with tempfile.TemporaryDirectory() as tmpdir:
rrd = tmpdir + "/tmp.rrd"

rr.init("rerun_example_test_recording")
rr.set_time_sequence("my_index", 1)
rr.log("log", rr.TextLog("Hello"))
rr.save(rrd)

recording = rr.dataframe.load_recording(rrd)
assert recording is not None

view = recording.view(index="my_index", contents="/**")
batches = view.select()
table = pa.Table.from_batches(batches, batches.schema)

# my_index, log_time, log_tick, indicator, text
assert table.num_columns == 5
assert table.num_rows == 1

recording = rr.dataframe.load_recording(pathlib.Path(tmpdir) / "tmp.rrd")
assert recording is not None

view = recording.view(index="my_index", contents="/**")
batches = view.select()
table = pa.Table.from_batches(batches, batches.schema)

# my_index, log_time, log_tick, indicator, text
assert table.num_columns == 5
assert table.num_rows == 1


class TestDataframe:
def setup_method(self) -> None:
rr.init("rerun_example_test_recording")
Expand Down

0 comments on commit 46e0b3b

Please sign in to comment.