Skip to content

Commit

Permalink
Implement fix in codegen + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 11, 2024
1 parent 9c3b9a1 commit 9d7a0d8
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 34 deletions.
4 changes: 3 additions & 1 deletion crates/build/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,11 @@ fn quote_arrow_serialization(
return Ok(unindent(
r##"
if isinstance(data, str):
array = [data]
array: Union[list[str], npt.ArrayLike] = [data]
elif isinstance(data, Sequence):
array = [str(datum) for datum in data]
elif isinstance(data, np.ndarray):
array = data
else:
array = [str(data)]
Expand Down
2 changes: 1 addition & 1 deletion crates/store/re_types/definitions/rerun/datatypes/utf8.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace rerun.datatypes;
table Utf8 (
"attr.arrow.transparent",
"attr.python.aliases": "str",
"attr.python.array_aliases": "str, Sequence[str]",
"attr.python.array_aliases": "str, Sequence[str], npt.ArrayLike",
"attr.rust.derive": "Default, PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.rust.override_crate": "re_types_core",
"attr.rust.repr": "transparent",
Expand Down
6 changes: 5 additions & 1 deletion rerun_py/rerun_sdk/rerun/datatypes/entity_path.py

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

18 changes: 14 additions & 4 deletions rerun_py/rerun_sdk/rerun/datatypes/utf8.py

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

24 changes: 0 additions & 24 deletions rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py

This file was deleted.

6 changes: 5 additions & 1 deletion rerun_py/tests/test_types/components/affix_fuzzer10.py

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

6 changes: 5 additions & 1 deletion rerun_py/tests/test_types/components/affix_fuzzer9.py

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

6 changes: 5 additions & 1 deletion rerun_py/tests/test_types/datatypes/string_component.py

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

27 changes: 27 additions & 0 deletions rerun_py/tests/unit/test_utf8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import numpy as np
from rerun import datatypes


def test_utf8_batch_single() -> None:
single_string = "hello"
list_of_one_string = ["hello"]
array_of_one_string = np.array(["hello"])

assert (
datatypes.Utf8Batch(single_string).as_arrow_array() == datatypes.Utf8Batch(list_of_one_string).as_arrow_array()
)

assert (
datatypes.Utf8Batch(single_string).as_arrow_array() == datatypes.Utf8Batch(array_of_one_string).as_arrow_array()
)


def test_utf8_batch_many() -> None:
list_of_strings = ["hello", "world"]
array_of_strings = np.array(["hello", "world"])

assert (
datatypes.Utf8Batch(list_of_strings).as_arrow_array() == datatypes.Utf8Batch(array_of_strings).as_arrow_array()
)

0 comments on commit 9d7a0d8

Please sign in to comment.