使用 pyarrow dtype 创建 dask 数组

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

在 pandas 中,我可以通过以下方式创建带有 pyarrow dtype 的系列:

>>> import pandas as pd

>>> s = pd.Series([1,2,3]).astype("int64[pyarrow]")
>>> s.dtype
int64[pyarrow]

我没有找到如何使用 Dask 来做到这一点。

我尝试过:

>>> import dask.config
>>> import dask.array as da
>>> dask.config.set({"array.pyarrow_dtype": True})

>>> s = da.array([1,2,3])
>>> s

返回一个 numpy int 64 dtype 的数组。

我还尝试了以下方法:

>>> import dask.array as da
>>> s = da.array([1,2,3], dtype="int64[pyarrow]")
TypeError: data type 'int64[pyarrow]' not understood

>>> import dask.array as da
>>> import pyarrow as pa
>>> s = da.array([1,2,3], pa.int64())

TypeError: Cannot interpret 'DataType(int64)' as a data type

可以吗?

pandas dask pyarrow apache-arrow dtype
1个回答
0
投票

dask.array 不直接支持 pyarrow。事实上,由于它们将代表(常规)numpy 数组,箭头不会提供任何好处。

IS 支持任意数组后端,支持 NEP18 (

__array_function__
),例如允许将 numpy 替换为 cupy。但是,我不相信这包含任何箭头结构 - 或者我不知道如何实现它。

您在 dask 中看到的箭头支持的引用特定于数据帧,并且通常(总是?)用于字符串。

© www.soinside.com 2019 - 2024. All rights reserved.