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

Python Components now implement the ComponentBatchLike interface #6543

Merged
merged 6 commits into from
Jun 12, 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
29 changes: 27 additions & 2 deletions crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ impl PythonCodeGenerator {
Archetype,
BaseExtensionType,
BaseBatch,
ComponentBatchMixin
ComponentBatchMixin,
ComponentMixin,
)
from {rerun_path}_converters import (
int_or_none,
Expand Down Expand Up @@ -612,6 +613,10 @@ fn code_for_struct(
));
}

if *kind == ObjectKind::Component {
superclasses.push("ComponentMixin".to_owned());
}

if let Some(deprecation_notice) = obj.deprecation_notice() {
code.push_unindented(format!(r#"@deprecated("""{deprecation_notice}""")"#), 1);
}
Expand All @@ -634,6 +639,10 @@ fn code_for_struct(

code.push_indented(1, quote_obj_docs(obj), 0);

if *kind == ObjectKind::Component {
code.push_indented(1, "_BATCH_TYPE = None", 1);
}

if ext_class.has_init {
code.push_indented(
1,
Expand Down Expand Up @@ -775,7 +784,23 @@ fn code_for_struct(

match kind {
ObjectKind::Archetype => (),
ObjectKind::Datatype | ObjectKind::Component => {
ObjectKind::Component => {
code.push_indented(
0,
quote_arrow_support_from_obj(reporter, arrow_registry, ext_class, objects, obj),
1,
);

code.push_indented(
0,
format!(
"# This is patched in late to avoid circular dependencies.
{name}._BATCH_TYPE = {name}Batch # type: ignore[assignment]"
),
1,
);
}
ObjectKind::Datatype => {
code.push_indented(
0,
quote_arrow_support_from_obj(reporter, arrow_registry, ext_class, objects, obj),
Expand Down
26 changes: 26 additions & 0 deletions rerun_py/rerun_sdk/rerun/_baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ def component_name(self) -> str:
return self._ARROW_TYPE._TYPE_NAME # type: ignore[attr-defined, no-any-return]


class ComponentMixin(ComponentBatchLike):
"""
Makes components adhere to the ComponentBatchLike interface.

A single component will always map to a batch of size 1.

The class using the mixin must define the `_BATCH_TYPE` field, which should be a subclass of `BaseBatch`.
"""

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

Part of the `ComponentBatchLike` logging interface.
"""
return self._BATCH_TYPE._ARROW_TYPE._TYPE_NAME # type: ignore[attr-defined, no-any-return]

def as_arrow_array(self) -> pa.Array:
"""
The component as an arrow batch.

Part of the `ComponentBatchLike` logging interface.
"""
return self._BATCH_TYPE([self]).as_arrow_array() # type: ignore[attr-defined, no-any-return]


@catch_and_log_exceptions(context="creating empty array")
def _empty_pa_array(type: pa.DataType) -> pa.Array:
if type == pa.null():
Expand Down
4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/annotation_context.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/arrows2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/arrows3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/asset3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/axes3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/bar_chart.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/boxes2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/boxes3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/clear.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/depth_image.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/disconnected_space.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/image.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/line_strips2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/line_strips3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/pinhole.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/points2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/points3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/scalar.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/segmentation_image.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/series_line.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/series_point.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/tensor.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/text_document.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/text_log.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/transform3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/view_coordinates.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/archetypes/background.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading