Skip to content

Commit

Permalink
Add support for NumPy arrays to the Utf8 datatype arrow serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 11, 2024
1 parent b248c88 commit 9c3b9a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 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: 24 additions & 0 deletions rerun_py/rerun_sdk/rerun/datatypes/utf8_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Sequence

import numpy as np
import pyarrow as pa

if TYPE_CHECKING:
from . import Utf8ArrayLike


class Utf8Ext:
@staticmethod
def native_to_pa_array_override(data: Utf8ArrayLike, data_type: pa.DataType) -> pa.Array:
if isinstance(data, str):
array = [data]
elif isinstance(data, Sequence):
array = [str(datum) for datum in data]
elif isinstance(data, np.ndarray):
array = data
else:
array = [str(data)]

return pa.array(array, type=data_type)

0 comments on commit 9c3b9a1

Please sign in to comment.