| #!/usr/bin/env python3 | |
| """ | |
| Convert a JSONL file (records per line) to Parquet with a stable schema. | |
| Usage: | |
| python scripts/jsonl_to_parquet.py manifests/preview.jsonl manifests/preview.parquet | |
| python scripts/jsonl_to_parquet.py manifests/dev.jsonl manifests/dev.parquet | |
| Requires: pandas + pyarrow | |
| """ | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import pandas as pd | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("src", type=Path) | |
| ap.add_argument("dst", type=Path) | |
| args = ap.parse_args() | |
| records = [] | |
| with args.src.open("r", encoding="utf-8") as f: | |
| for line in f: | |
| if not line.strip(): | |
| continue | |
| records.append(json.loads(line)) | |
| # Use pandas to write parquet; let pyarrow infer nested lists | |
| df = pd.DataFrame.from_records(records) | |
| args.dst.parent.mkdir(parents=True, exist_ok=True) | |
| df.to_parquet(args.dst, index=False) | |
| print(f"Wrote {args.dst}") | |
| if __name__ == "__main__": | |
| main() | |