maxframe.dataframe.infer_dtype#
- maxframe.dataframe.infer_dtype(obj: Any) ArrowDtype | ExternalBlobDtype[源代码]#
从 Python 对象推断 MaxFrame 兼容的数据类型。
从对象创建单元素 PyArrow 数组以推断其类型,然后使用 dtype() 函数转换为 MaxFrame 兼容的数据类型。
- 参数:
obj (Any) -- 用于推断数据类型的 Python 对象。可以是:- 标量值(int、float、bool、str、bytes)- 列表/元组(用于列表/数组类型)- 字典(用于结构类型)- Blob 对象(SolidBlob)- PyArrow 支持的任何其他 Python 对象
- 返回:
推断出的对象数据类型。
- 返回类型:
ArrowDtype or ExternalBlobDtype
- 抛出:
TypeError -- 如果对象类型不受支持或无法推断数据类型。
示例
>>> import maxframe.dataframe as md >>> md.infer_dtype(42) ArrowDtype(int64[pyarrow])
>>> md.infer_dtype(3.14) ArrowDtype(double[pyarrow])
>>> md.infer_dtype("hello") StringDtype(pyarrow)
>>> md.infer_dtype([1, 2, 3]) ArrowDtype(list<item: int64>[pyarrow])
>>> md.infer_dtype({"a": 1, "b": 2}) ArrowDtype(struct<a: int64, b: int64>[pyarrow])