Fix corrupted parquet files (footer was never written on upload)

#1
by rvsagar9567 - opened

Fix corrupted parquet files (footers were never written on upload)

The two parquet files currently on main are unreadable for both
pyarrow and the Hugging Face dataset viewer:

ArrowInvalid: Parquet magic bytes not found in footer. Either the file is
corrupted or this is not a parquet file.

This branch β€” fix-corrupted-parquets β€” fixes both files. No data was lost; the existing on-Hub bodies were intact, only the trailing footer + length + closing PAR1 magic were missing.

Root cause

File Status on main Recovery
data/chunk-000/file-000.parquet leading PAR1 βœ“, page bodies intact, no trailing PAR1 footer rebuilt from page-header scan
meta/episodes/chunk-000/file-000.parquet same truncation pattern regenerated from the data parquet + videos on disk
meta/tasks.parquet OK unchanged

For the data parquet, walking the body via Thrift Compact PageHeaders consumed every byte without trailing garbage:

  • 6,800 pages = (1 dictionary + 1 data) Γ— 17 columns Γ— 200 row groups.
  • Sum of num_values across data pages = 10,397,576 = 13 scalars Γ— 125,272 + (30 + 14 + 14 + 12) list-elements Γ— 125,272.
  • Per-row-group row counts (556, 654, 671, …, 664) sum to 125,272 = total_frames from meta/info.json.
  • Number of row groups = 200 = total_episodes.

This pattern (PAR1 head, no PAR1 tail, body fully parses) is exactly the signature of an upload (or writer) that was killed mid-finalisation.

What this branch does

Commit 1 β€” cc65151 fix(data): rebuild missing parquet footer

A synthesised FileMetaData Thrift Compact footer is appended to a copy of the file (followed by the 4-byte little-endian footer length and the closing PAR1 magic). The first 37,450,342 bytes of the recovered file are SHA-256-identical to the original body β€” only metadata was added.

>>> import datasets
>>> ds = datasets.load_dataset(
...     "axiboai/piper-stack-scripted",
...     revision="fix-corrupted-parquets",
...     data_files="data/chunk-000/file-000.parquet",
... )["train"]
>>> ds
Dataset({
    features: ['observation.state', 'observation.ee_pose', 'action.joint_position',
               'action.ee_delta', 'metadata.demonstrator_id', ..., 'task_index'],
    num_rows: 125272,
})
>>> len(set(ds["episode_index"]))
200
>>> ds["metadata.task_variant"][0]
'stack_red_on_blue'

Commit 2 β€” 8d87002 fix(meta/episodes): regenerate per-episode index parquet

meta/episodes/chunk-000/file-000.parquet was rebuilt from scratch using the (now-readable) data parquet plus the videos on disk:

  1. Group rows by episode_index β†’ 200 episodes, lengths 529–700 frames, total 125,272.
  2. For each video feature, walk the existing videos/<key>/chunk-000/file-*.mp4 files (3, 2, 2, 1 files respectively) and assign each episode to a (chunk_index, file_index, from_timestamp, to_timestamp) matching LeRobot's writer roll-over rule (file boundaries align with episode boundaries).
  3. Compute per-episode {min, max, mean, std, count, q01, q10, q50, q90, q99} for every numeric and video feature using the same RunningQuantileStats algorithm as lerobot.datasets.compute_stats (single deterministic ~125-frame sample per episode for video features, normalised to [0, 1] with shape (3, 1, 1)).
  4. Materialise the 165-column LeRobot v3 schema and write it as a single SNAPPY-compressed row group.

dataset_to_index of the last episode is 125,272, exactly matching the data parquet row count.

Verification

After this branch is merged:

import pyarrow.parquet as pq
from huggingface_hub import HfFileSystem
fs = HfFileSystem()

for path in ["data/chunk-000/file-000.parquet",
             "meta/episodes/chunk-000/file-000.parquet",
             "meta/tasks.parquet"]:
    with fs.open(f"datasets/axiboai/piper-stack-scripted/{path}", "rb") as f:
        md = pq.read_metadata(f)
    print(path, md.num_rows, "rows", md.num_columns, "cols")

Should print:

data/chunk-000/file-000.parquet 125272 rows 17 cols
meta/episodes/chunk-000/file-000.parquet 200 rows 165 cols
meta/tasks.parquet 1 rows 2 cols

The dataset viewer should also start working again once the merge lands.

Notes

  • Per-episode video std values are (0, 0, 0). This matches what LeRobot's own writer produces (batch ** 2 overflows on uint8 in RunningQuantileStats.update, which clamps to 0 in np.maximum(0, variance)). The aggregated meta/stats.json std is non-zero because aggregation uses delta_means**2 over float64, sidestepping the overflow.
  • meta/info.json declares video.codec: h264 but the actual .mp4 files are encoded with AV1 (libdav1d). That's an upstream metadata bug worth fixing in a follow-up β€” it doesn't affect this recovery.
Publish this branch
This branch is in draft mode, publish it to be able to merge.

Sign up or log in to comment