Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column property accessors for selectors and descriptors #7752

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions rerun_py/rerun_bindings/rerun_bindings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,68 @@ from .types import AnyColumn, ComponentLike, IndexValuesLike, ViewContentsLike
class IndexColumnDescriptor:
"""A column containing the index values for when the component data was updated."""

def name(self) -> str:
"""
The name of the index.

This property is read-only.
"""
...

class IndexColumnSelector:
"""A selector for an index column."""

def __init__(self, index: str): ...
def name(self) -> str:
"""
The name of the index.

This property is read-only.
"""
...

class ComponentColumnDescriptor:
"""A column containing the component data."""

@property
def entity_path(self) -> str:
"""
The entity path.

This property is read-only.
"""
...

@property
def component_name(self) -> str:
"""
The component name.

This property is read-only.
"""
...

class ComponentColumnSelector:
"""A selector for a component column."""

def __init__(self, entity_path: str, component: ComponentLike): ...
@property
def entity_path(self) -> str:
"""
The entity path.

This property is read-only.
"""
...

@property
def component_name(self) -> str:
"""
The component name.

This property is read-only.
"""
...

class Schema:
"""The schema representing all columns in a [`Recording`][]."""
Expand Down
30 changes: 30 additions & 0 deletions rerun_py/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl PyIndexColumnDescriptor {
fn __repr__(&self) -> String {
format!("Index(timeline:{})", self.0.timeline.name())
}

#[getter]
fn name(&self) -> &str {
self.0.timeline.name()
}
}

impl From<TimeColumnDescriptor> for PyIndexColumnDescriptor {
Expand All @@ -78,6 +83,11 @@ impl PyIndexColumnSelector {
fn __repr__(&self) -> String {
format!("Index(timeline:{})", self.0.timeline)
}

#[getter]
fn name(&self) -> &str {
&self.0.timeline
}
}

/// Python binding for [`ComponentColumnDescriptor`]
Expand Down Expand Up @@ -105,6 +115,16 @@ impl PyComponentColumnDescriptor {
fn __eq__(&self, other: &Self) -> bool {
self.0 == other.0
}

#[getter]
fn entity_path(&self) -> String {
self.0.entity_path.to_string()
}

#[getter]
fn component_name(&self) -> &str {
&self.0.component_name
}
}

impl From<PyComponentColumnDescriptor> for ComponentColumnDescriptor {
Expand Down Expand Up @@ -135,6 +155,16 @@ impl PyComponentColumnSelector {
self.0.entity_path, self.0.component_name
)
}

#[getter]
fn entity_path(&self) -> String {
self.0.entity_path.to_string()
}

#[getter]
fn component_name(&self) -> &str {
&self.0.component_name
}
}

/// Python binding for [`AnyColumn`] type-alias.
Expand Down
17 changes: 17 additions & 0 deletions rerun_py/tests/unit/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ def test_recording_info(self) -> None:
assert self.recording.application_id() == APP_ID
assert self.recording.recording_id() == str(RECORDING_ID)

def test_schema(self) -> None:
schema = self.recording.schema()

assert len(schema.index_columns()) == 3
# Points3DIndicator, Position3D, Color
assert len(schema.component_columns()) == 3

assert schema.index_columns()[0].name == "log_tick"
assert schema.index_columns()[1].name == "log_time"
assert schema.index_columns()[2].name == "my_index"
assert schema.component_columns()[0].entity_path == "/points"
assert schema.component_columns()[0].component_name == "rerun.components.Color"
assert schema.component_columns()[1].entity_path == "/points"
assert schema.component_columns()[1].component_name == "rerun.components.Points3DIndicator"
assert schema.component_columns()[2].entity_path == "/points"
assert schema.component_columns()[2].component_name == "rerun.components.Position3D"

def test_full_view(self) -> None:
view = self.recording.view(index="my_index", contents="points")

Expand Down
5 changes: 5 additions & 0 deletions scripts/ci/python_check_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def load_runtime_signatures(module_name: str) -> TotalSignature:
class_def[method_name] = inspect.signature(method_obj)
except Exception:
pass
# Get property getters
for method_name, method_obj in inspect.getmembers(
obj, lambda o: o.__class__.__name__ == "getset_descriptor"
):
class_def[method_name] = Signature(parameters=[Parameter("self", Parameter.POSITIONAL_ONLY)])
signatures[name] = class_def

return signatures
Expand Down
Loading