Datasets:
File size: 2,742 Bytes
f9b150b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #!/usr/bin/env python3
"""Local structural checks for the BehaviorBench NeurIPS artifact."""
import json, re, sys
from pathlib import Path
import pyarrow as pa
import pyarrow.parquet as pq
ROOT=Path(__file__).resolve().parents[1]
errors=[]
required=["README.md","DATASET_CARD.md","LICENSE","CHANGELOG.md","croissant.json","docs/RESPONSIBLE_AI.md"]
for x in required:
if not (ROOT/x).exists(): errors.append(f"missing {x}")
try: meta=json.loads((ROOT/"croissant.json").read_text())
except Exception as e: errors.append(f"invalid croissant JSON: {e}"); meta={}
rai=["rai:dataLimitations","rai:dataBiases","rai:personalSensitiveInformation","rai:dataUseCases","rai:dataSocialImpact","rai:hasSyntheticData","rai:dataCollection"]
for k in rai:
if k not in meta: errors.append(f"missing Croissant RAI field {k}")
files={p.relative_to(ROOT).as_posix():p for top in (ROOT/"dataset",ROOT/"benchmark") for p in top.rglob("*.parquet") if "evaluation/sources" not in p.as_posix()}
dists={x.get("@id"):x for x in meta.get("distribution",[])}
records={x.get("name"):x for x in meta.get("recordSet",[])}
for rel,p in files.items():
if rel not in dists: errors.append(f"no distribution for {rel}")
if rel not in records: errors.append(f"no recordSet for {rel}")
else:
schema=pq.ParquetFile(p).schema_arrow
actual=set(schema.names)
described={x.get("name") for x in records[rel].get("field",[])}
if not described.issubset(actual):
errors.append(f"schema contains unknown fields for {rel}")
omitted=actual-described
for name in omitted:
t=schema.field(name).type
# Current mlcroissant record generation cannot reliably cast
# nested Parquet structs, including list<struct<...>> columns.
nested_struct = pa.types.is_struct(t) or (
(pa.types.is_list(t) or pa.types.is_large_list(t))
and pa.types.is_struct(t.value_type)
)
if not nested_struct:
errors.append(f"unexplained omitted field {name} for {rel}")
for rel in dists:
if rel not in files: errors.append(f"distribution path not found: {rel}")
# Relative Markdown links.
for p in [ROOT/"README.md",ROOT/"DATASET_CARD.md",*sorted((ROOT/"docs").glob("*.md"))]:
for link in re.findall(r"\[[^]]+\]\(([^)]+)\)",p.read_text()):
if "://" not in link and not link.startswith("#") and not (p.parent/link).resolve().exists():
errors.append(f"broken link {p.relative_to(ROOT)} -> {link}")
if errors:
print("FAIL")
print("\n".join(f"- {x}" for x in errors));sys.exit(1)
print(f"PASS: {len(files)} Parquet distributions/record sets; required RAI fields and local links present.")
|