| """Emit JSON statistics for the train parquet, for use by the dataset-card skill.""" |
| from __future__ import annotations |
|
|
| import json |
| import sys |
| from pathlib import Path |
|
|
| import pyarrow.parquet as pq |
|
|
| REPO = Path(__file__).resolve().parent.parent |
| PARQUET = REPO / "data" / "train-00000-of-00001.parquet" |
|
|
|
|
| def main() -> int: |
| if not PARQUET.exists(): |
| print(json.dumps({"error": f"missing {PARQUET}"})) |
| return 1 |
| pf = pq.ParquetFile(PARQUET) |
| table = pf.read() |
| num_rows = table.num_rows |
| num_bytes_disk = PARQUET.stat().st_size |
| num_bytes_uncompressed = sum(chunk.nbytes for c in table.columns for chunk in c.chunks) |
| out = { |
| "num_rows": num_rows, |
| "num_bytes_disk": num_bytes_disk, |
| "num_bytes_uncompressed": int(num_bytes_uncompressed), |
| "schema": [{"name": f.name, "type": str(f.type)} for f in table.schema], |
| "parquet_relpath": "data/train-00000-of-00001.parquet", |
| } |
| print(json.dumps(out, ensure_ascii=False, indent=2)) |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|