-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for NumPy arrays to the
Utf8
datatype arrow serializer
- Loading branch information
Showing
2 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |