This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 5982b1241a [python] Fix LeRobot task imports without Pandas index 
metadata (#11058)
5982b1241a is described below

commit 5982b1241aef46d8da03205373e4600c16e213b0
Author: XiaoHongbo <[email protected]>
AuthorDate: Tue Nov 10 12:09:36 2026 +0800

    [python] Fix LeRobot task imports without Pandas index metadata (#11058)
---
 .../pypaimon/multimodal/lerobot/dataset.py         |  8 +++-
 .../pypaimon/multimodal/lerobot/source.py          | 11 +++++
 .../pypaimon/tests/multimodal_lerobot_test.py      | 48 ++++++++++++++++++++++
 3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/paimon-python/pypaimon/multimodal/lerobot/dataset.py 
b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
index e4e61a607b..ceac2444fb 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/dataset.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
@@ -37,6 +37,7 @@ import pyarrow as pa
 
 from pypaimon.common.options.core_options import CoreOptions
 from pypaimon.multimodal.lerobot.metadata import (
+    _PANDAS_METADATA_OPTION,
     _companion_table_identifiers,
     _restore_pandas_metadata,
     _tag_snapshot_id,
@@ -1006,7 +1007,12 @@ def _episode_dataset(table):
 
 def _component_dataframe(table, index_field):
     data = _read_arrow(table).sort_by(index_field)
-    return _restore_pandas_metadata(table, data).to_pandas()
+    frame = _restore_pandas_metadata(table, data).to_pandas()
+    if table.table_schema.options.get(_PANDAS_METADATA_OPTION) is None:
+        label = index_field[:-len("_index")]
+        if label in frame.columns:
+            frame = frame.set_index(label)
+    return frame
 
 
 def _metadata_object(table, name):
diff --git a/paimon-python/pypaimon/multimodal/lerobot/source.py 
b/paimon-python/pypaimon/multimodal/lerobot/source.py
index 07e7dfb487..aa78e1ca1b 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/source.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/source.py
@@ -499,6 +499,17 @@ class _SourceUriReaderFactory:
 
 def _pandas_index_column(schema, component):
     encoded = (schema.metadata or {}).get(b"pandas")
+    if encoded is None:
+        # Arrow-written task tables may omit Pandas index metadata.
+        expected = {component + "_index", component}
+        if len(schema.names) == 2 and set(schema.names) == expected \
+                and (pa.types.is_string(schema.field(component).type)
+                     or 
pa.types.is_large_string(schema.field(component).type)):
+            return component
+        raise ValueError(
+            "LeRobot %s metadata must contain a Pandas index or the "
+            "canonical %s and %s columns."
+            % (component, component + "_index", component))
     try:
         pandas_metadata = json.loads(encoded.decode("utf-8"))
         index_columns = pandas_metadata["index_columns"]
diff --git a/paimon-python/pypaimon/tests/multimodal_lerobot_test.py 
b/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
index c90650021c..c383a8e92b 100644
--- a/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
+++ b/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
@@ -90,6 +90,7 @@ from pypaimon.multimodal.lerobot.schema import (
     _validate_v3_required_features,
 )
 from pypaimon.multimodal.lerobot.source import (
+    _pandas_index_column,
     _LeRobotSource,
     _RemoteLeRobotDataset,
     _import_lerobot_dataset,
@@ -191,6 +192,22 @@ class LeRobotValidationTest(unittest.TestCase):
         with self.assertRaises(ValueError):
             _dataset_fps(value)
 
+    def test_arrow_task_columns_without_pandas_metadata(self):
+        for component in ("task", "subtask"):
+            for text_type in (pa.string(), pa.large_string()):
+                schema = pa.schema([(component, text_type), (component + 
"_index", pa.int64())])
+                self.assertEqual(component, _pandas_index_column(schema, 
component))
+            for fields in (
+                    [(component + "_index", pa.int64())],
+                    [(component + "_index", pa.int64()), ("description", 
pa.string())],
+                    [(component + "_index", pa.int64()), (component, 
pa.int64())]):
+                with self.subTest(component=component, fields=fields):
+                    with self.assertRaises(ValueError):
+                        _pandas_index_column(pa.schema(fields), component)
+            schema = pa.schema([(component + "_index", pa.int64()), 
(component, pa.string())])
+            with self.assertRaises(ValueError):
+                _pandas_index_column(schema.with_metadata({b"pandas": 
b"invalid"}), component)
+
     def test_episode_validation_projects_batched_hf_metadata(self):
         try:
             from datasets import Dataset
@@ -4257,6 +4274,37 @@ class LeRobotImportTest(unittest.TestCase):
         }
         self.assertEqual(1, len(files))
 
+    def test_import_arrow_tasks_and_subtasks(self):
+        source = self.temp_dir / "arrow_tasks"
+        shutil.copytree(self.image_source, source)
+        info_path = source / "meta" / "info.json"
+        info = json.loads(info_path.read_text())
+        info["features"]["subtask_index"] = {"dtype": "int64", "shape": [1], 
"names": None}
+        info_path.write_text(json.dumps(info))
+        for path in (source / "data").rglob("*.parquet"):
+            data = pq.read_table(path)
+            pq.write_table(data.append_column(
+                "subtask_index", pa.array([0] * data.num_rows, 
type=pa.int64())), path)
+        task_path = source / "meta" / "tasks.parquet"
+        tasks = pq.read_table(task_path).to_pandas()
+        expected_tasks = tasks.index.tolist()
+        pq.write_table(pa.table({"task_index": tasks["task_index"].tolist(),
+                                "task": expected_tasks}), task_path)
+        pq.write_table(pa.table({"subtask_index": [0], "subtask": ["reach"]}),
+                       source / "meta" / "subtasks.parquet")
+
+        for name, location in (("local_tasks", source), ("uri_tasks", 
source.as_uri())):
+            with self.subTest(source=name):
+                self.connection.load_from_lerobot(name, location, 
tag_name="train")
+                dataset = pmm.PaimonLeRobotDataset(
+                    self.connection.get_table(name), tag_name="train")
+                self.assertEqual(expected_tasks, 
dataset.meta.tasks.index.tolist())
+                self.assertEqual(["reach"], 
dataset.meta.subtasks.index.tolist())
+                row = dataset[0]
+                self.assertEqual(expected_tasks[int(row["task_index"])], 
row["task"])
+                self.assertEqual("reach", row["subtask"])
+                self.assertEqual(info["total_frames"], len(dataset))
+
     def test_import_publishes_optional_subtasks(self):
         import pandas as pd
 

Reply via email to