maxframe.dataframe.dtype#
- maxframe.dataframe.dtype(type)[源代码]#
MaxFrame DataFrame 操作的推荐数据类型。
将各种类型表示转换为 MaxFrame 兼容的数据类型。大多数类型返回 pd.ArrowDtype,blob 类型返回 ExternalBlobDtype。
- 参数:
type (str, np.dtype, pd.ExtensionDtype, odps.types.DataType, pa.DataType, or Python type class) -- 转换为 MaxFrame 兼容 dtype 的类型。支持的输入类型:- str: 类型字符串,如 'int64'、'string'、'blob'、'list<item: int64>' 等 - np.dtype: NumPy dtype 对象 - pd.ExtensionDtype: Pandas 扩展 dtype - odps.types.DataType: ODPS 数据类型(需要 odps 包)- pa.DataType: PyArrow 数据类型 - Python 类型类:int, float, bool, str, bytes (int -> int64, float -> float64, bool -> bool, str -> StringDtype(pyarrow), bytes -> binary)
- 返回:
MaxFrame 操作中使用的推荐数据类型。对于 blob 类型返回 ExternalBlobDtype,其他类型返回 ArrowDtype。
- 返回类型:
ArrowDtype or ExternalBlobDtype
- 抛出:
TypeError -- 如果输入类型不受支持或无法转换。
示例
>>> import maxframe.dataframe as md >>> md.dtype("int64") ArrowDtype(int64[pyarrow])
>>> md.dtype("blob") ExternalBlobDtype()
>>> import numpy as np >>> md.dtype(np.dtype('float32')) ArrowDtype(float[pyarrow])
>>> from odps import types as odps_types >>> md.dtype(odps_types.string) ArrowDtype(string[pyarrow])
>>> md.dtype(int) ArrowDtype(int64[pyarrow])
>>> md.dtype(float) ArrowDtype(double[pyarrow])
>>> md.dtype(str) StringDtype(pyarrow)
>>> md.dtype(bytes) ArrowDtype(binary[pyarrow])