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.
Add python bindings for new dataframe APIs (rerun-io#7357)
### What - First pass at implementing APIs for: rerun-io#7455 - Introduces a new mechanism for directly exposing rust types into the python bridge via a .pyi definition Example notebook for testing ``` pixi run py-build-examples pixi run -e examples jupyter notebook tests/python/dataframe/examples.ipynb ``` ### Future work: - More docs / help strings - Remaining API features ### 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/7357?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/7357?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/7357) - [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
Showing
13 changed files
with
1,214 additions
and
2 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,5 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, TypeAlias, Union | ||
|
||
from .rerun_bindings import * |
Empty file.
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,107 @@ | ||
from typing import Optional, Sequence | ||
|
||
import pyarrow as pa | ||
|
||
from .types import AnyColumn, ComponentLike, ViewContentsLike | ||
|
||
class ControlColumnDescriptor: | ||
"""A control-level column such as `RowId`.""" | ||
|
||
class ControlColumnSelector: | ||
"""A selector for a control column.""" | ||
|
||
@staticmethod | ||
def row_id() -> ControlColumnSelector: ... | ||
|
||
class IndexColumnDescriptor: | ||
"""A column containing the index values for when the component data was updated.""" | ||
|
||
class IndexColumnSelector: | ||
"""A selector for an index column.""" | ||
|
||
def __init__(self, timeline: str): ... | ||
|
||
class ComponentColumnDescriptor: | ||
"""A column containing the component data.""" | ||
|
||
def with_dictionary_encoding(self) -> ComponentColumnDescriptor: ... | ||
|
||
class ComponentColumnSelector: | ||
"""A selector for a component column.""" | ||
|
||
def __new__(cls, entity_path: str, component_type: ComponentLike): ... | ||
def with_dictionary_encoding(self) -> ComponentColumnSelector: ... | ||
|
||
class Schema: | ||
"""The schema representing all columns in a [`Recording`][].""" | ||
|
||
def control_columns(self) -> list[ControlColumnDescriptor]: ... | ||
def index_columns(self) -> list[IndexColumnDescriptor]: ... | ||
def component_columns(self) -> list[ComponentColumnDescriptor]: ... | ||
def column_for(self, entity_path: str, component: ComponentLike) -> Optional[ComponentColumnDescriptor]: ... | ||
|
||
class RecordingView: | ||
""" | ||
A view of a recording restricted to a given index, containing a specific set of entities and components. | ||
Can only be created by calling `view(...)` on a `Recording`. | ||
The only type of index currently supported is the name of a timeline. | ||
The view will only contain a single row for each unique value of the index. If the same entity / component pair | ||
was logged to a given index multiple times, only the most recent row will be included in the view, as determined | ||
by the `row_id` column. This will generally be the last value logged, as row_ids are guaranteed to be monotonically | ||
increasing when data is sent from a single process. | ||
""" | ||
|
||
def filter_range_sequence(self, start: int, end: int) -> RecordingView: | ||
"""Filter the view to only include data between the given index sequence numbers.""" | ||
... | ||
|
||
def filter_range_seconds(self, start: float, end: float) -> RecordingView: | ||
"""Filter the view to only include data between the given index time values.""" | ||
... | ||
|
||
def filter_range_nanos(self, start: int, end: int) -> RecordingView: | ||
"""Filter the view to only include data between the given index time values.""" | ||
... | ||
|
||
def select(self, columns: Sequence[AnyColumn]) -> list[pa.RecordBatch]: ... | ||
|
||
class Recording: | ||
"""A single recording.""" | ||
|
||
def schema(self) -> Schema: ... | ||
def view(self, index: str, contents: ViewContentsLike) -> RecordingView: ... | ||
|
||
class RRDArchive: | ||
"""An archive loaded from an RRD, typically containing 1 or more recordings or blueprints.""" | ||
|
||
def num_recordings(self) -> int: ... | ||
def all_recordings(self) -> list[Recording]: ... | ||
|
||
def load_recording(filename: str) -> Recording: | ||
""" | ||
Load a single recording from an RRD. | ||
Will raise a `ValueError` if the file does not contain exactly one recording. | ||
Parameters | ||
---------- | ||
filename : str | ||
The path to the file to load. | ||
""" | ||
... | ||
|
||
def load_archive(filename: str) -> RRDArchive: | ||
""" | ||
Load a rerun archive file from disk. | ||
Parameters | ||
---------- | ||
filename : str | ||
The path to the file to load. | ||
""" | ||
... |
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,37 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Sequence, TypeAlias, Union | ||
|
||
if TYPE_CHECKING: | ||
from rerun._baseclasses import ComponentMixin | ||
|
||
from .rerun_bindings import ( | ||
ComponentColumnDescriptor as ComponentColumnDescriptor, | ||
ComponentColumnSelector as ComponentColumnSelector, | ||
ControlColumnDescriptor as ControlColumnDescriptor, | ||
ControlColumnSelector as ControlColumnSelector, | ||
TimeColumnDescriptor as TimeColumnDescriptor, | ||
TimeColumnSelector as TimeColumnSelector, | ||
) | ||
|
||
|
||
ComponentLike: TypeAlias = Union[str, type["ComponentMixin"]] | ||
|
||
AnyColumn: TypeAlias = Union[ | ||
"ControlColumnDescriptor", | ||
"TimeColumnDescriptor", | ||
"ComponentColumnDescriptor", | ||
"ControlColumnSelector", | ||
"TimeColumnSelector", | ||
"ComponentColumnSelector", | ||
] | ||
|
||
AnyComponentColumn: TypeAlias = Union[ | ||
"ComponentColumnDescriptor", | ||
"ComponentColumnSelector", | ||
] | ||
|
||
ViewContentsLike: TypeAlias = Union[ | ||
str, | ||
dict[str, Union[AnyColumn, Sequence[ComponentLike]]], | ||
] |
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,20 @@ | ||
from __future__ import annotations | ||
|
||
from rerun_bindings import ( | ||
ComponentColumnDescriptor as ComponentColumnDescriptor, | ||
ComponentColumnSelector as ComponentColumnSelector, | ||
ControlColumnDescriptor as ControlColumnDescriptor, | ||
ControlColumnSelector as ControlColumnSelector, | ||
Recording as Recording, | ||
RRDArchive as RRDArchive, | ||
Schema as Schema, | ||
TimeColumnDescriptor as TimeColumnDescriptor, | ||
TimeColumnSelector as TimeColumnSelector, | ||
load_archive as load_archive, | ||
load_recording as load_recording, | ||
) | ||
from rerun_bindings.types import ( | ||
AnyColumn as AnyColumn, | ||
AnyComponentColumn as AnyComponentColumn, | ||
ComponentLike as ComponentLike, | ||
) |
Oops, something went wrong.