HDF5 转 Lance
更新时间:2026-11-23
简介
把一个 HDF5 文件转成一张 Lance 表。第 0 维长度相同的数据集按行对齐,各成一列,第 i 行 = 每个数据集的第 i 个元素;dtype 原样保留。适合 action/...、state/... 这类机器人时间序列。
功能描述
- 行数默认取出现最多的第 0 维长度,也可用
num_rows指定 - 标量列保持原 dtype;子数组存为定长列表,原形状记在字段 metadata
hdf5:shape - 列名为数据集相对
group的路径,.换成_ - 不对齐的数据集和 group 属性写进表的 schema metadata(键
hdf5)
算子参数
输入
| 输入 | 含义 |
|---|---|
| input_path | HDF5 文件路径(本地) |
| output_path | Lance 表路径,本地或 bos:// / s3:// |
输出
| 输出 | 含义 |
|---|---|
| lance | 输出 Lance 表路径(large_string),失败为 None |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| group | str | "/" | 只转这个 group 下的数据集 |
| num_rows | int 或 None | None | 行数,None 自动推断 |
| exclude | list[str] 或 None | None | 不转的数据集或 group 路径 |
| skip_unaligned | bool | False | 不对齐的数据集只记元信息、不存数据 |
| max_metadata_bytes | int | 4194304 | 写进 schema metadata 的总字节上限 |
| overwrite | bool | False | 输出表已存在时是否重写 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.file.hdf5_to_lance import Hdf5ToLance
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18ds = daft.from_pydict({
19 "input": ["/data/agibot/proprio_stats/327/648649/proprio_stats.h5"],
20 "output": ["/data/lance/agibot_648649.lance"],
21 })
22 ds = ds.with_column(
23 "lance",
24 aihc_udf(
25 Hdf5ToLance,
26 construct_args={"group": "/", "num_rows": None},
27 num_cpus=1,
28 num_gpus=0,
29 concurrency=4,
30 batch_size=1,
31 )(col("input"), col("output")),
32 )
33 ds.show()
评价此篇文章
