Skip to content

Commit 5cb70ff

Browse files
committed
Add support for NumPy arrays to the Utf8 datatype arrow serializer
1 parent 9f23ae0 commit 5cb70ff

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

rerun_py/rerun_sdk/rerun/datatypes/utf8.py

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Sequence
4+
5+
import numpy as np
6+
import pyarrow as pa
7+
8+
if TYPE_CHECKING:
9+
from . import Utf8ArrayLike
10+
11+
12+
class Utf8Ext:
13+
@staticmethod
14+
def native_to_pa_array_override(data: Utf8ArrayLike, data_type: pa.DataType) -> pa.Array:
15+
if isinstance(data, str):
16+
array = [data]
17+
elif isinstance(data, Sequence):
18+
array = [str(datum) for datum in data]
19+
elif isinstance(data, np.ndarray):
20+
array = data
21+
else:
22+
array = [str(data)]
23+
24+
return pa.array(array, type=data_type)

0 commit comments

Comments
 (0)