maxframe.dataframe.read_lance#

maxframe.dataframe.read_lance(path, version: int = None, asof: str = None, columns: list = None, filters: str = None, index_col=None, dtype_backend: str = <no_default>, default_index_type: DefaultIndexType | str = None, storage_options: dict = None, *, dtypes: Series = None, index_dtypes: Series = None, memory_scale: int = None, merge_small_files: bool = True, merge_small_file_options: dict = None, session=None, run_kwargs: dict = None, **kwargs)[源代码]#

从文件路径加载 Lance 数据集,返回 DataFrame。

参数:
  • path (str) -- 任何有效的字符串路径都是可接受的。字符串可以是 URL。对于阿里云 OSS URL,格式为:oss://<endpoint>/<bucket>/<path>。示例:oss://oss-cn-beijing.aliyuncs.com/my-bucket/dataset。对于 S3 URL,格式为:s3://<bucket>/<path>

  • version (int, optional) -- 要读取的数据集的特定版本。如果未指定,则读取最新版本。

  • asof (str, optional) -- 时间点读取的时间戳。格式:ISO 8601 日期时间字符串。不能与 version 参数一起使用。

  • columns (list, optional) -- 如果不为 None,则只从数据集中读取这些列。

  • filters (str or list, optional) --

    Filter expression for predicate pushdown. Supports: - SQL-like filter strings accepted by Lance - CNF filters like [[('age', '>', 18), ('city', '==', 'Beijing')]]

    used by MaxFrame predicate pushdown

    The alias filter=... is also accepted for compatibility.

  • index_col (int, str, sequence of int/str, or False, default None) -- 用作 DataFrame 行标签的列,可以是字符串名称或列索引。如果给定了 int/str 序列,则使用 MultiIndex。如果为 False,则不使用任何列作为索引(忽略数据集中的任何 pandas 元数据)。如果为 None,则在可用时使用 pandas 元数据,否则回退到 default_index_type。

  • default_index_type ({None, 'range', 'incremental'}, default None) -- 如果未指定 index_col,则指定要生成的索引类型。如果未指定,将使用 options.dataframe.default_index_type

  • dtype_backend ({'numpy', 'pyarrow'}, default 'numpy') -- 应用于结果 DataFrame 的后端数据类型。

  • storage_options (dict, optional) -- Options for storage connection. For Aliyun OSS with RAM role: {'role_arn': 'acs:ram::xxx:role/name'}

  • memory_scale (int, optional) -- 实际内存占用除以原始文件大小的比例。

  • merge_small_files (bool, default True) -- 将小的 Lance 片段合并为更大的块,以获得更好的并行处理效率。

  • merge_small_file_options (dict, optional) -- 合并小文件的选项。

  • **kwargs -- 任何额外的 kwargs 都会传递给 lance。

返回类型:

MaxFrame DataFrame

示例

>>> import maxframe.dataframe as md
>>> # Read from Aliyun OSS with RAM role
>>> df = md.read_lance(
...     "oss://oss-cn-beijing.aliyuncs.com/my-bucket/dataset",
...     storage_options={"role_arn": "acs:ram::1234567890:role/maxframe-oss"}
... )
>>> # Read specific version
>>> df = md.read_lance(
...     "oss://oss-cn-beijing.aliyuncs.com/my-bucket/dataset",
...     version=1,
...     storage_options={"role_arn": "acs:ram::1234567890:role/maxframe-oss"}
... )
>>> # Read with filter
>>> df = md.read_lance(
...     "oss://oss-cn-beijing.aliyuncs.com/my-bucket/dataset",
...     filters="`age` > 18",
...     storage_options={"role_arn": "acs:ram::1234567890:role/maxframe-oss"}
... )