Skip to content

Commit

Permalink
Python-codegen arrow serilization of structs of datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 29, 2024
1 parent 2faaf68 commit 5834ec7
Show file tree
Hide file tree
Showing 42 changed files with 170 additions and 230 deletions.
34 changes: 32 additions & 2 deletions crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1821,13 +1821,43 @@ fn quote_arrow_support_from_obj(
/// Only implemented for some cases.
fn quote_arrow_serialization(
_reporter: &Reporter,
_objects: &Objects,
objects: &Objects,
obj: &Object,
) -> Result<String, String> {
let Object { name, .. } = obj;

match obj.class {
ObjectClass::Struct => Err("We lack codegen for arrow-serialization of structs".to_owned()),
ObjectClass::Struct => {
let mut code = String::new();

code.push_indented(0, "from .. import datatypes", 2);

code.push_indented(0, &format!("if isinstance(data, {name}):"), 1);
code.push_indented(1, "data = [data]", 2);

code.push_indented(0, "return pa.StructArray.from_arrays(", 1);
code.push_indented(1, "[", 1);
for field in &obj.fields {
let Type::Object(field_fqname) = &field.typ else {
return Err(
"We lack codegen for arrow-serialization of general structs".to_owned()
);
};
let field_obj = &objects[field_fqname];
let field_type_name = &field_obj.name;
let field_name = &field.name;
let field_batch_type = format!("datatypes.{field_type_name}Batch");
let field_array = format!("[x.{field_name} for x in data]");
let field_fwd =
format!("{field_batch_type}({field_array}).as_arrow_array().storage,");
code.push_indented(2, &field_fwd, 1);
}
code.push_indented(1, "],", 1);
code.push_indented(1, "fields=list(data_type),", 1);
code.push_indented(0, ")", 1);

Ok(code)
}

ObjectClass::Enum => {
// Generate case-insensitive string-to-enum conversion:
Expand Down

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

15 changes: 12 additions & 3 deletions rerun_py/rerun_sdk/rerun/blueprint/datatypes/visible_time_range.py

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

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

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

16 changes: 13 additions & 3 deletions rerun_py/rerun_sdk/rerun/datatypes/aabb2d.py

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

27 changes: 0 additions & 27 deletions rerun_py/rerun_sdk/rerun/datatypes/aabb2d_ext.py

This file was deleted.

16 changes: 13 additions & 3 deletions rerun_py/rerun_sdk/rerun/datatypes/class_description_map_elem.py

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

This file was deleted.

2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/datatypes/float32.py

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

16 changes: 13 additions & 3 deletions rerun_py/rerun_sdk/rerun/datatypes/keypoint_pair.py

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

47 changes: 0 additions & 47 deletions rerun_py/rerun_sdk/rerun/datatypes/keypoint_pair_ext.py

This file was deleted.

15 changes: 12 additions & 3 deletions rerun_py/rerun_sdk/rerun/datatypes/material.py

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

31 changes: 0 additions & 31 deletions rerun_py/rerun_sdk/rerun/datatypes/material_ext.py

This file was deleted.

0 comments on commit 5834ec7

Please sign in to comment.