直接创建`pyarrow.StructScalar`的方法?

问题描述 投票:0回答:1

我知道我可以通过铸造创建一个

pa.StructScalar

import pyarrow as pa
import pyarrow.compute as pac

struct_scalar = pac.cast(
    {"hello": "greetings", "world": 5},
    target_type=pa.struct([("hello", pa.string()), ("world", pa.int16())]),
)
print(f"{struct_scalar=}")
print(f"{struct_scalar.type=}")

但是还有其他方法可以创建结构体标量吗?

python pyarrow
1个回答
0
投票

使用

pyarrow.scalar

import pyarrow as pa

scalar = pa.scalar(
    {"hello": "greetings", "world": 5},
    type=pa.struct([("hello", pa.string()), ("world", pa.int16())]),
)
© www.soinside.com 2019 - 2024. All rights reserved.