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 fed938f5dc [python] Store grouped LeRobot Episode fields as VARIANT 
(#11092)
fed938f5dc is described below

commit fed938f5dcfd611dc09610bfef36755656368e15
Author: XiaoHongbo <[email protected]>
AuthorDate: Wed Nov 11 16:12:56 2026 +0800

    [python] Store grouped LeRobot Episode fields as VARIANT (#11092)
---
 docs/docs/pypaimon/lerobot.md                      | 16 ++--
 .../pypaimon/multimodal/lerobot/aggregate.py       | 90 +++++++++++++---------
 .../pypaimon/multimodal/lerobot/dataset.py         |  5 +-
 .../pypaimon/tests/lerobot_aggregate_test.py       | 64 ++++++++++-----
 4 files changed, 113 insertions(+), 62 deletions(-)

diff --git a/docs/docs/pypaimon/lerobot.md b/docs/docs/pypaimon/lerobot.md
index 3f2c0cd6c9..01abb3bc90 100644
--- a/docs/docs/pypaimon/lerobot.md
+++ b/docs/docs/pypaimon/lerobot.md
@@ -87,16 +87,18 @@ forced to `BIGINT`.
 | `dataset_to_index` | Source integer type | Exclusive end of that frame 
range. |
 | `length` | Source integer type | Number of frames; equals `dataset_to_index 
- dataset_from_index`. |
 | `tasks` | Source task-label list | Task texts used by the Episode, rather 
than frame task IDs. |
-| `meta`, `data`, `videos`, `stats` | JSON `STRING` columns | Grouped source 
fields describing metadata locations, data shards, per-camera video 
locations/timestamps, and per-Episode feature statistics. Empty groups are 
`{}`. |
-| Other source fields | Source type, or a JSON `STRING` for a `/` prefix group 
| Custom Episode metadata, such as quality labels or camera calibration. |
+| `meta`, `data`, `videos`, `stats` | `VARIANT` columns | Grouped source 
fields describing metadata locations, data shards, per-camera video 
locations/timestamps, and per-Episode feature statistics. Empty groups are 
`{}`. |
+| Other source fields | Source type, or a `VARIANT` for a `/` prefix group | 
Custom Episode metadata, such as quality labels or camera calibration. |
 
 For list imports, a field such as `data/chunk_index` becomes the
 `"chunk_index"` key inside `_episodes.data`. A field such as
 `videos/observation.images.front/from_timestamp` becomes the
 `"observation.images.front/from_timestamp"` key inside `_episodes.videos`.
 Likewise, `camera_intrinsics/head_left` becomes the `"head_left"` key in a
-`camera_intrinsics` JSON column. Episode `stats` is grouped by feature and then
+`camera_intrinsics` VARIANT column. Episode `stats` is grouped by feature and 
then
 statistic, for example `{"action":{"mean":[0.1,0.2]}}`.
+In Python, decode a scanned VARIANT value with
+`GenericVariant.from_arrow_struct(value).to_python()`.
 
 These data/video locations describe the original LeRobot files. Paimon reads
 the imported media through the frame table's BLOB values.
@@ -157,7 +159,7 @@ For a new import with a single source string and no 
`dataset_name` or non-empty
 still creates the same three tables. Its Dataset row has `index=0` and
 `name=null`, but frames and Episodes do not gain a source `dataset_index`.
 Episode fields such as `data/chunk_index` and `stats/action/mean` retain their
-original names and types instead of being grouped into JSON columns.
+original names and types instead of being grouped into VARIANT columns.
 
 To use the source-indexed schema above, or to append more sources later, pass
 `source=["/data/source_a"]`. Supplying `dataset_name` or non-empty
@@ -210,7 +212,7 @@ sources. [Dataset fields](#dataset-fields) describes the 
retained source metadat
 
 Grouped Episode fields must use JSON-native Arrow types: null, boolean, 
integer,
 floating point, string, list, or struct, including nested combinations.
-Binary, temporal, decimal, map, and extension types in these JSON groups are
+Binary, temporal, decimal, map, and extension types in these source groups are
 rejected before any target table is created. Episode fields without `/` retain
 their original names and Paimon-supported Arrow types as columns in 
`_episodes`;
 unsupported types are rejected before table creation.
@@ -229,7 +231,7 @@ require an import option.
 
 `schema_evolution=True` is the default. The importer plans the union of source
 columns before creating `_frames`, `_episodes`, and any declared extra
-`_datasets` columns. Episode fields with `/` are grouped by prefix into JSON:
+`_datasets` columns. Episode fields with `/` are grouped by prefix into 
VARIANT:
 `camera_intrinsics/head_left` becomes the `head_left` key in
 `_episodes.camera_intrinsics`. Other Episode fields retain their Arrow types.
 For appends, it compares the incoming columns with the existing table group and
@@ -237,6 +239,8 @@ adds new nullable columns. Existing rows read as null in 
those columns; incoming
 rows receive nulls for omitted optional columns. Existing optional columns are
 made nullable when necessary. All three component schemas are checked before
 catalog changes, and existing field IDs are preserved.
+Existing table groups with JSON `STRING` Episode columns must be re-imported to
+use the new VARIANT schema; append does not change those column types in place.
 Missing columns receive typed nulls. Optional columns become nullable; source
 indices, timestamps, task indices, and required Episode controls remain 
required.
 Common columns must have identical types, and common frame features must retain
diff --git a/paimon-python/pypaimon/multimodal/lerobot/aggregate.py 
b/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
index ce4e0d8bf6..d1e9d56268 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/aggregate.py
@@ -18,6 +18,7 @@
 
 import copy
 import json
+from decimal import Decimal
 from contextlib import ExitStack, contextmanager
 
 import numpy as np
@@ -25,6 +26,7 @@ import pyarrow as pa
 import pyarrow.compute as pc
 
 from pypaimon import Schema as PaimonSchema
+from pypaimon.data.generic_variant import GenericVariant
 from pypaimon.multimodal.arrow_utils import strict_arrow_table
 from pypaimon.multimodal.lerobot.loader import (
     _commit_messages, _prepare_dataset, _video_fps,
@@ -65,8 +67,12 @@ _REBUILT_INFO = {
     "data_files_size_in_mb", "video_files_size_in_mb", "features",
 }
 _DATASET_INDEX_COLUMN = "dataset_index"
-_EPISODE_JSON_GROUPS = ("meta", "data", "videos", "stats")
-_EPISODE_EXTRA_JSON_GROUP_DESCRIPTION = "pypaimon.lerobot.episode-json-group"
+_EPISODE_VARIANT_GROUPS = ("meta", "data", "videos", "stats")
+_EPISODE_EXTRA_VARIANT_GROUP_DESCRIPTION = 
"pypaimon.lerobot.episode-variant-group"
+_VARIANT_TYPE = pa.struct([
+    pa.field("value", pa.binary(), nullable=False),
+    pa.field("metadata", pa.binary(), nullable=False),
+])
 _SOURCE_TASKS_TYPE = pa.list_(pa.struct([
     pa.field("task_index", pa.int64(), nullable=False),
     pa.field("task", pa.string(), nullable=False),
@@ -157,17 +163,30 @@ def _json_native_arrow_type(data_type):
     return False
 
 
-def _episode_json_group(original, group):
+def _variant_value(value):
+    def preserve_large_integers(item):
+        if isinstance(item, int) and not isinstance(item, bool) \
+                and not -(1 << 63) <= item < (1 << 63):
+            return Decimal(item)
+        if isinstance(item, dict):
+            return {key: preserve_large_integers(child) for key, child in 
item.items()}
+        if isinstance(item, list):
+            return [preserve_large_integers(child) for child in item]
+        return item
+
+    variant = 
GenericVariant.from_python(preserve_large_integers(_json_value(value)))
+    return {"value": variant.value(), "metadata": variant.metadata()}
+
+
+def _episode_variant_group(original, group):
     prefix = group + "/"
-    return json.dumps(
-        _json_value({key[len(prefix):]: value
-                     for key, value in original.items()
-                     if key.startswith(prefix)}),
-        ensure_ascii=False, separators=(",", ":"))
+    return _variant_value({key[len(prefix):]: value
+                           for key, value in original.items()
+                           if key.startswith(prefix)})
 
 
-def _episode_json_groups(schema):
-    groups = dict.fromkeys(_EPISODE_JSON_GROUPS)
+def _episode_variant_groups(schema):
+    groups = dict.fromkeys(_EPISODE_VARIANT_GROUPS)
     for name in schema.names:
         if "/" in name:
             group, key = name.split("/", 1)
@@ -177,9 +196,9 @@ def _episode_json_groups(schema):
     return tuple(groups)
 
 
-def _validate_episode_json(table, source_index):
+def _validate_episode_variant(table, source_index):
     fields = [field for field in table.schema if "/" in field.name]
-    groups = _episode_json_groups(table.schema)
+    groups = _episode_variant_groups(table.schema)
     for field in fields:
         if not _json_native_arrow_type(field.type):
             raise ValueError(
@@ -190,7 +209,7 @@ def _validate_episode_json(table, source_index):
     for row_index, original in enumerate(table.select(names).to_pylist()):
         for group in groups:
             try:
-                _episode_json_group(original, group)
+                _episode_variant_group(original, group)
             except (TypeError, ValueError, OverflowError) as error:
                 raise ValueError(
                     "LeRobot source %d Episode row %d has invalid JSON-native "
@@ -343,12 +362,12 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
     info["features"] = features
     metadata = dict(first["metadata"])
     metadata["frame_schema"] = frame_schema
-    # Keep ungrouped fields typed and turn each slash prefix into one JSON 
column.
+    # Keep ungrouped fields typed and turn each slash prefix into one VARIANT 
column.
     groups = tuple(dict.fromkeys(group for plan in plans
-                                 for group in _episode_json_groups(
+                                 for group in _episode_variant_groups(
                                      plan["metadata"]["episodes_schema"])))
     if _DATASET_INDEX_COLUMN in groups:
-        raise ValueError("LeRobot Episode JSON group uses reserved column 
dataset_index.")
+        raise ValueError("LeRobot Episode VARIANT group uses reserved column 
dataset_index.")
     reserved_episode_fields = {_DATASET_INDEX_COLUMN, *groups}
     for ordinal, plan in enumerate(plans):
         conflicts = reserved_episode_fields.intersection(
@@ -359,13 +378,13 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
     schemas = []
     for plan in plans:
         source_schema = plan["metadata"]["episodes_schema"]
-        source_groups = _episode_json_groups(source_schema)
+        source_groups = _episode_variant_groups(source_schema)
         schemas.append(pa.schema(
             [field for field in source_schema if "/" not in field.name]
-            + [pa.field(group, pa.string(), nullable=False,
+            + [pa.field(group, _VARIANT_TYPE, nullable=False,
                         metadata={b"description":
-                                  
_EPISODE_EXTRA_JSON_GROUP_DESCRIPTION.encode("utf-8")})
-               for group in source_groups if group not in 
_EPISODE_JSON_GROUPS]))
+                                  
_EPISODE_EXTRA_VARIANT_GROUP_DESCRIPTION.encode("utf-8")})
+               for group in source_groups if group not in 
_EPISODE_VARIANT_GROUPS]))
     metadata["episodes_schema"] = _merge_schemas(schemas, schema_evolution, 
_EPISODE_CONTROL_COLUMNS)
     frame_offset = episode_offset = 0
     for ordinal, plan in enumerate(plans):
@@ -380,7 +399,7 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
                 _video_fps(other, other["features"][name], name)
             for table in _validated_episode_tables(
                     plan["metadata"], plan["videos"], 
check_episode_fps=mixed_fps):
-                _validate_episode_json(table, ordinal)
+                _validate_episode_variant(table, ordinal)
         except ValueError as error:
             raise ValueError("LeRobot source %d: %s" % (ordinal, error)) from 
error
         plan["frame_offset"] = frame_offset
@@ -396,10 +415,10 @@ def _plan_merge(plans, extra_dataset_fields=None, 
schema_evolution=True,
     metadata["subtasks_table"] = _vocabulary(plans, "subtasks", 
existing_sources)
     for field in (
             pa.field(_DATASET_INDEX_COLUMN, pa.int64(), nullable=False),
-            pa.field("meta", pa.string(), nullable=False),
-            pa.field("data", pa.string(), nullable=False),
-            pa.field("videos", pa.string(), nullable=False),
-            pa.field("stats", pa.string(), nullable=False)):
+            pa.field("meta", _VARIANT_TYPE, nullable=False),
+            pa.field("data", _VARIANT_TYPE, nullable=False),
+            pa.field("videos", _VARIANT_TYPE, nullable=False),
+            pa.field("stats", _VARIANT_TYPE, nullable=False)):
         metadata["episodes_schema"] = metadata["episodes_schema"].append(field)
     episode_names = metadata["episodes_schema"].names
     if len(episode_names) != len(set(episode_names)):
@@ -504,19 +523,19 @@ def _transform_frames(plan, batch, episode):
 def _merged_episodes(plans, schema):
     extra_groups = tuple(dict.fromkeys(
         group for plan in plans
-        for group in _episode_json_groups(plan["metadata"]["episodes_schema"])
-        if group not in _EPISODE_JSON_GROUPS))
+        for group in 
_episode_variant_groups(plan["metadata"]["episodes_schema"])
+        if group not in _EPISODE_VARIANT_GROUPS))
     for plan in plans:
         for table in _source_episode_tables(plan["metadata"]):
-            source_groups = set(_episode_json_groups(table.schema))
+            source_groups = set(_episode_variant_groups(table.schema))
             records = []
             for original in table.to_pylist():
                 row = {name: original[name] for name in schema.names
                        if name in original}
                 for group in ("meta", "data", "videos"):
-                    row[group] = _episode_json_group(original, group)
+                    row[group] = _episode_variant_group(original, group)
                 for group in extra_groups:
-                    row[group] = (_episode_json_group(original, group)
+                    row[group] = (_episode_variant_group(original, group)
                                   if group in source_groups
                                   else None)
                 stats = {}
@@ -535,8 +554,7 @@ def _merged_episodes(plans, schema):
                             metric: None for metric in stats["subtask_index"]}
                 for name, values in plan["control_stats"][episode].items():
                     stats[name] = values
-                row["stats"] = json.dumps(
-                    _json_value(stats), ensure_ascii=False, separators=(",", 
":"))
+                row["stats"] = _variant_value(stats)
                 records.append(row)
             yield pa.Table.from_pylist(records, schema=schema)
 
@@ -632,20 +650,20 @@ def _import_sources(connection, table_name, sources, 
batch_size, options,
         else:
             table, tables, source_rows, ranges = existing
             existing_episode_schema = _target_schema(tables["episodes"])
-            existing_groups = set(_EPISODE_JSON_GROUPS)
+            existing_groups = set(_EPISODE_VARIANT_GROUPS)
             existing_groups.update(
                 field.name for field in existing_episode_schema
                 if (field.metadata or {}).get(b"description") ==
-                _EPISODE_EXTRA_JSON_GROUP_DESCRIPTION.encode("utf-8"))
+                _EPISODE_EXTRA_VARIANT_GROUP_DESCRIPTION.encode("utf-8"))
             incoming_groups = set(group for plan in plans
-                                  for group in _episode_json_groups(
+                                  for group in _episode_variant_groups(
                                       plan["metadata"]["episodes_schema"]))
             conflicts = sorted(
                 name for name in set(existing_episode_schema.names)
                 & set(metadata["episodes_schema"].names)
                 if (name in existing_groups) != (name in incoming_groups))
             if conflicts:
-                raise ValueError("LeRobot append Episode JSON groups conflict 
with "
+                raise ValueError("LeRobot append Episode VARIANT groups 
conflict with "
                                  "plain columns: %s." % conflicts)
             first_info = ranges[0][0]
             old_features = {}
diff --git a/paimon-python/pypaimon/multimodal/lerobot/dataset.py 
b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
index d66d330f61..98a2be6969 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/dataset.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
@@ -37,6 +37,7 @@ from types import SimpleNamespace
 import pyarrow as pa
 import pyarrow.compute as pc
 
+from pypaimon.data.generic_variant import GenericVariant
 from pypaimon.multimodal.lerobot.aggregate import (
     _CONTROLS, _REBUILT_INFO, _merge_stats,
 )
@@ -1229,7 +1230,9 @@ def _merged_source_stats(sources, episodes_table):
     columns = _target_schema(episodes_table).names
     if "stats" in columns:
         stats_rows = _read_arrow(episodes_table, 
["stats"])["stats"].to_pylist()
-        decoded_rows = [json.loads(raw) for raw in stats_rows if raw]
+        decoded_rows = [GenericVariant.from_arrow_struct(raw).to_python()
+                        if isinstance(raw, dict) else json.loads(raw)
+                        for raw in stats_rows if raw]
         for name in _CONTROLS:
             parts = [row[name] for row in decoded_rows if name in row
                      and row[name].get("count") is not None]
diff --git a/paimon-python/pypaimon/tests/lerobot_aggregate_test.py 
b/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
index 5992b93662..a3bb910683 100644
--- a/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
+++ b/paimon-python/pypaimon/tests/lerobot_aggregate_test.py
@@ -27,7 +27,9 @@ import pyarrow as pa
 import pyarrow.parquet as pq
 import pytest
 
+from pypaimon import Schema as PaimonSchema
 from pypaimon.catalog.catalog_exception import TableNotExistException
+from pypaimon.data.generic_variant import GenericVariant
 import pypaimon.multimodal as pm
 from pypaimon.multimodal.lerobot import aggregate
 from pypaimon.multimodal.lerobot.aggregate import _batch_stats, 
_transform_frames
@@ -37,6 +39,10 @@ from pypaimon.table.row.blob import Blob, 
VideoFrameDescriptor
 pytestmark = pytest.mark.skipif(sys.version_info < (3, 10), reason="LeRobot 
import requires Python 3.10+")
 
 
+def variant_value(value):
+    return None if value is None else 
GenericVariant.from_arrow_struct(value).to_python()
+
+
 def source(root, tasks=("pick", "place"), subtasks=("reach", "grasp"), 
video=False, value=0, fps=10, frames=5):
     root.mkdir(parents=True)
     meta = root / "meta"
@@ -232,7 +238,7 @@ def 
test_append_rejects_episode_group_plain_column_collision(setup, group_first)
     conn.load_from_lerobot("robot", [sources[0]])
     before = episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist()
 
-    with pytest.raises(ValueError, match="JSON groups conflict with plain 
columns"):
+    with pytest.raises(ValueError, match="VARIANT groups conflict with plain 
columns"):
         conn.append_to_lerobot("robot", sources[1])
 
     assert episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist() == before
@@ -250,7 +256,7 @@ def test_append_preserves_episode_group_kind(setup):
     conn.load_from_lerobot("robot", [sources[0]])
     conn.append_to_lerobot("robot", sources[1])
     actual = episode_rows(conn, 
"robot_episodes")["camera_intrinsics"].to_pylist()
-    assert [json.loads(value) for value in actual] == [
+    assert [variant_value(value) for value in actual] == [
         {"head_left": [0.]}, {"head_left": [1.]},
         {"head_left": [1.]}, {"head_left": [2.]},
     ]
@@ -262,9 +268,9 @@ def 
test_append_episode_task_stats_use_group_vocabulary(setup):
     conn.append_to_lerobot("robot", sources[1])
 
     episodes = episode_rows(conn, "robot_episodes").to_pylist()
-    task_means = [json.loads(row["stats"])["task_index"]["mean"][0]
+    task_means = [variant_value(row["stats"])["task_index"]["mean"][0]
                   for row in episodes]
-    subtask_means = [json.loads(row["stats"])["subtask_index"]["mean"][0]
+    subtask_means = [variant_value(row["stats"])["subtask_index"]["mean"][0]
                      for row in episodes]
     assert task_means == [0, 1, 1, 2]
     assert subtask_means == pytest.approx([0.5, 1 / 3, 1.5, 4 / 3])
@@ -465,7 +471,7 @@ def test_merge_numbering_stats_and_training(setup, 
import_parallelism):
     assert episodes["dataset_from_index"].to_pylist() == [0, 2, 0, 2]
     assert episodes["dataset_to_index"].to_pylist() == [2, 5, 2, 5]
     assert not any(c.startswith("stats/") for c in episodes.column_names)
-    episode_stats = [json.loads(value) for value in 
episodes["stats"].to_pylist()]
+    episode_stats = [variant_value(value) for value in 
episodes["stats"].to_pylist()]
     assert [item["index"]["mean"] for item in episode_stats] == [
         [0.5], [3.0], [5.5], [8.0]]
     assert all("q50" not in item["index"] for item in episode_stats)
@@ -500,7 +506,7 @@ def test_merge_numbering_stats_and_training(setup, 
import_parallelism):
     assert selected[0]["episode_index"].item() == 2
 
 
-def test_merge_keeps_source_specific_episode_statistics_in_json(setup):
+def test_merge_keeps_source_specific_episode_statistics_in_variant(setup):
     conn, sources = setup
     for index, uri in enumerate(sources):
         path = Path(uri[7:]) / "meta/episodes/chunk-000/file-000.parquet"
@@ -513,21 +519,41 @@ def 
test_merge_keeps_source_specific_episode_statistics_in_json(setup):
 
     conn.load_from_lerobot("merged", sources)
     episodes = episode_rows(conn, "merged_episodes")
-    assert episodes.schema.field("stats").type == pa.string()
-    assert all(episodes.schema.field(name).type == pa.string()
+    assert episodes.schema.field("stats").type == aggregate._VARIANT_TYPE
+    assert next(field for field in 
PaimonSchema.from_pyarrow_schema(episodes.schema).fields
+                if field.name == "stats").type.type == "VARIANT"
+    assert all(episodes.schema.field(name).type == aggregate._VARIANT_TYPE
                for name in ("meta", "data", "videos", "stats"))
     assert not any(name.startswith(("meta/", "data/", "videos/", "stats/"))
                    for name in episodes.column_names)
     for row in episodes.to_pylist():
-        stats = json.loads(row["stats"])
+        stats = variant_value(row["stats"])
         assert stats["source_%d" % row["dataset_index"]]["mean"] == [
             row["dataset_index"] + 0.5]
         assert "q50" not in stats["index"]
-        assert json.loads(row["meta"]) == {"episodes/chunk_index": 
row["dataset_index"]}
-        assert json.loads(row["data"]) == {
+        assert variant_value(row["meta"]) == {"episodes/chunk_index": 
row["dataset_index"]}
+        assert variant_value(row["data"]) == {
             "chunk_index": 0, "file_index": 0,
             "vendor_%d" % row["dataset_index"]: "source"}
-        assert json.loads(row["videos"]) == {}
+        assert variant_value(row["videos"]) == {}
+    from pypaimon.multimodal.lerobot.dataset import _merged_source_stats
+    merged_stats = _merged_source_stats(
+        rows(conn, "merged_datasets").to_pylist(),
+        conn.get_table("merged_episodes").raw_table)
+    np.testing.assert_allclose(merged_stats["index"]["mean"], [4.5])
+
+
+def test_episode_variant_preserves_uint64(setup):
+    conn, sources = setup
+    path = Path(sources[0][7:]) / "meta/episodes/chunk-000/file-000.parquet"
+    table = pq.read_table(path).append_column(
+        "meta/large_id", pa.array([2**64 - 1, None], type=pa.uint64()))
+    pq.write_table(table, path)
+
+    conn.load_from_lerobot("merged", [sources[0]])
+    episodes = episode_rows(conn, "merged_episodes").to_pylist()
+    assert variant_value(episodes[0]["meta"])["large_id"] == Decimal(2**64 - 1)
+    assert variant_value(episodes[1]["meta"])["large_id"] is None
 
 
 @pytest.mark.parametrize("name,values", [
@@ -906,7 +932,7 @@ def test_video_sources_with_identical_paths(tmp_path, 
import_parallelism):
     episodes = episode_rows(conn, "merged_episodes")
     assert not any(name.startswith("videos/") for name in 
episodes.column_names)
     for episode in episodes.to_pylist():
-        video = json.loads(episode["videos"])
+        video = variant_value(episode["videos"])
         assert set(video) == {"camera/" + suffix for suffix in (
             "chunk_index", "file_index", "from_timestamp", "to_timestamp")}
     for source_index, uri in enumerate(sources):
@@ -1182,7 +1208,7 @@ def test_merge_nullable_subtask_import(setup, tmp_path, 
import_parallelism, all_
     assert not batch["subtask_index_is_valid"][1].item()
     if all_null:
         assert "subtask_index" not in metadata(conn, "stats")
-        assert all(all(metric is None for metric in json.loads(value)
+        assert all(all(metric is None for metric in variant_value(value)
                        ["subtask_index"].values()) for value in
                    rows(conn, "merged_episodes")["stats"].to_pylist())
     if not all_null:
@@ -1292,7 +1318,7 @@ def 
test_reconstructed_subtask_stats_use_output_schema(setup, import_parallelism
         pq.write_table(episodes.cast(schema), path)
     conn.load_from_lerobot("merged", sources, parallelism=import_parallelism)
     episodes = episode_rows(conn, "merged_episodes")
-    stats = [json.loads(value) for value in episodes["stats"].to_pylist()]
+    stats = [variant_value(value) for value in episodes["stats"].to_pylist()]
     assert [value.get("subtask_index", {}).get("mean") for value in 
stats[::2]] == (
         [None, None] if empty_episode else [[0.0], [1.0]])
     assert not any(name.startswith("stats/") for name in episodes.column_names)
@@ -1684,7 +1710,7 @@ def test_merge_source_specific_episode_extensions(setup, 
import_parallelism, rev
     conn.load_from_lerobot("merged", sources, parallelism=import_parallelism, 
tag_name="train")
     data = episode_rows(conn, "merged_episodes")
     assert data.schema.field("vendor_note").nullable
-    assert data.schema.field("camera_intrinsics").type == pa.string()
+    assert data.schema.field("camera_intrinsics").type == 
aggregate._VARIANT_TYPE
     assert data.schema.field("camera_intrinsics").nullable
     for ordinal, uri in enumerate(sources):
         source_index = original.index(uri)
@@ -1695,7 +1721,7 @@ def test_merge_source_specific_episode_extensions(setup, 
import_parallelism, rev
             [1, 2] if source_index == 0 else [3, 4])
         assert values["shared_note"].to_pylist() == (
             ["shared", "note"] if source_index == 0 else [None, "note"])
-        assert [None if value is None else json.loads(value)
+        assert [None if value is None else variant_value(value)
                 for value in values["camera_intrinsics"].to_pylist()] == (
                     [None, None] if source_index == 0 else [
                         {"head_left": [1.] * 8}, {"head_left": [2.] * 8}])
@@ -2108,8 +2134,8 @@ def test_schema_evolution_unions_three_tables(setup, 
import_parallelism, reverse
             [1., 2., 3., 4., 5.] if first else [None] * 5)
         assert data["pressure"].slice(ordinal * 5, 5).to_pylist() == (
             [None] * 5 if first else [6., 7., 8., 9., 10.])
-        assert json.loads(episodes[ordinal * 2]["meta"]).get("note") == ("a" 
if first else None)
-        assert json.loads(episodes[ordinal * 2]["meta"]).get("score") == (None 
if first else 0.5)
+        assert variant_value(episodes[ordinal * 2]["meta"]).get("note") == 
("a" if first else None)
+        assert variant_value(episodes[ordinal * 2]["meta"]).get("score") == 
(None if first else 0.5)
         assert datasets[ordinal]["notes"] == (None if first else "# Notes")
         assert datasets[ordinal]["config"] == ([("model", '{"name":"model"}')] 
if first else None)
     assert metadata(conn, "stats")["temperature"]["count"] == [5]

Reply via email to