Skip to content

Commit

Permalink
Fix Utf8Pair arrow serialisation + WIP tests and Numpy API
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Nov 20, 2024
1 parent 3facb25 commit 7adad6b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace rerun.datatypes;
/// Stores a tuple of UTF-8 strings.
table Utf8Pair (
"attr.docs.unreleased",
"attr.python.aliases": "Sequence[datatypes.Utf8Like]",
"attr.python.aliases": "Tuple[datatypes.Utf8Like, datatypes.Utf8Like]",
"attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord"
) {
/// The first string.
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_space_view_graph/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl TypedComponentFallbackProvider<VisualBounds2D> for GraphSpaceView {
return VisualBounds2D::default();
};

match state.layout.bounding_rect() {
match state.layout_state.bounding_rect() {
Some(rect) if valid_bound(&rect) => rect.into(),
_ => VisualBounds2D::default(),
}
Expand Down
6 changes: 3 additions & 3 deletions crates/viewer/re_space_view_graph/src/ui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
/// This state is preserved between frames, but not across Viewer sessions.
#[derive(Default)]
pub struct GraphSpaceViewState {
pub layout: LayoutState,
pub layout_state: LayoutState,

pub show_debug: bool,

Expand All @@ -24,7 +24,7 @@ pub struct GraphSpaceViewState {

impl GraphSpaceViewState {
pub fn layout_ui(&mut self, ui: &mut egui::Ui) {
let Some(rect) = self.layout.bounding_rect() else {
let Some(rect) = self.layout_state.bounding_rect() else {
return;
};
ui.grid_left_hand_label("Layout")
Expand All @@ -46,7 +46,7 @@ impl GraphSpaceViewState {

pub fn simulation_ui(&mut self, ui: &mut egui::Ui) {
if ui.button("Reset simulation").clicked() {
self.layout.reset();
self.layout_state.reset();
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_space_view_graph/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl SpaceViewClass for GraphSpaceView {
return Some(width / height);
}

if let Some(rect) = state.layout.bounding_rect() {
if let Some(rect) = state.layout_state.bounding_rect() {
let width = rect.width().abs();
let height = rect.height().abs();
return Some(width / height);
Expand Down Expand Up @@ -145,8 +145,8 @@ impl SpaceViewClass for GraphSpaceView {
let bounds: blueprint::components::VisualBounds2D =
bounds_property.component_or_fallback(ctx, self, state)?;

let layout_was_empty = state.layout.is_none();
let layout = state.layout.get(
let layout_was_empty = state.layout_state.is_none();
let layout = state.layout_state.get(
query.timeline,
query.latest_at,
graphs.iter().map(|(_, graph)| graph),
Expand Down Expand Up @@ -220,7 +220,7 @@ impl SpaceViewClass for GraphSpaceView {
// Update stored bounds on the state, so visualizers see an up-to-date value.
state.world_bounds = Some(bounds);

if state.layout.is_in_progress() {
if state.layout_state.is_in_progress() {
ui.ctx().request_repaint();
}

Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/datatypes/utf8pair.py

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

10 changes: 5 additions & 5 deletions rerun_py/rerun_sdk/rerun/datatypes/utf8pair_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def native_to_pa_array_override(data: Utf8PairArrayLike, data_type: pa.DataType)
from . import Utf8Batch, Utf8Pair

if isinstance(data, Utf8Pair):
data = [data]

strings = [_utf8_pair_converter(item) for item in data]
strings = [data]
else:
strings = [_utf8_pair_converter(item) for item in data]

string0 = [pair.first for pair in strings]
string1 = [pair.second for pair in strings]

string0_array = Utf8Batch(string0).as_arrow_array().storage
string1_array = Utf8Batch(string1).as_arrow_array().storage
string0_array = Utf8Batch(string0).as_arrow_array()
string1_array = Utf8Batch(string1).as_arrow_array()

return pa.StructArray.from_arrays(
arrays=[string0_array, string1_array],
Expand Down
25 changes: 25 additions & 0 deletions rerun_py/tests/unit/test_utf8pair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

from rerun import datatypes


def test_utf8pair_batch_single() -> None:
single_pair_batches = [
datatypes.Utf8PairBatch(datatypes.Utf8Pair("one", "two")),
datatypes.Utf8PairBatch([("one", "two")]),
datatypes.Utf8PairBatch([("one", datatypes.Utf8("two"))]),
datatypes.Utf8PairBatch([(datatypes.Utf8("one"), datatypes.Utf8("two"))]),
datatypes.Utf8PairBatch([(datatypes.Utf8("one"), "two")]),
]

for batch in single_pair_batches[1:]:
assert single_pair_batches[0].as_arrow_array() == batch.as_arrow_array()


def test_utf8pair_batch_multiple() -> None:
pass
# TODO
# single_pair_batches = [
# datatypes.Utf8PairBatch([datatypes.Utf8Pair("one", "two"), datatypes.Utf8Pair("three", "four")]),
# datatypes.Utf8PairBatch([("one", "two"), ("three", "four")]),
# ]

0 comments on commit 7adad6b

Please sign in to comment.