-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathread_parquet.py
More file actions
91 lines (74 loc) · 2.1 KB
/
Copy pathread_parquet.py
File metadata and controls
91 lines (74 loc) · 2.1 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pathlib import Path
import argparse
import json
import random
import pandas as pd
def pretty_print_value(v, max_str_len=3000):
"""Pretty print a cell value."""
if isinstance(v, (dict, list)):
try:
s = json.dumps(v, ensure_ascii=False, indent=2)
except Exception:
s = str(v)
else:
s = str(v)
if len(s) > max_str_len:
s = s[:max_str_len] + "\n... [truncated]"
return s
def show_sample(df, idx, max_str_len=3000):
print("\n" + "=" * 100)
print(f"Sample index: {idx}")
print("=" * 100)
row = df.iloc[idx]
for col in df.columns:
print(f"\n--- {col} ---")
print(pretty_print_value(row[col], max_str_len=max_str_len))
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--file",
type=str,
default="/root/math/data/sft_qwen3_1p7b_generated_openthoughts_math.parquet",
help="Path to parquet file",
)
parser.add_argument(
"--num-samples",
type=int,
default=3,
help="Number of random samples to show",
)
parser.add_argument(
"--seed",
type=int,
default=42,
help="Random seed",
)
parser.add_argument(
"--max-str-len",
type=int,
default=3000,
help="Maximum printed length per field",
)
args = parser.parse_args()
file_path = Path(args.file)
if not file_path.exists():
raise FileNotFoundError(f"File not found: {file_path}")
print(f"Reading: {file_path}")
df = pd.read_parquet(file_path)
print("\n=== Basic Info ===")
print(f"shape: {df.shape}")
print(f"columns: {list(df.columns)}")
n = len(df)
if n == 0:
print("\nDataset is empty.")
return
k = min(args.num_samples, n)
random.seed(args.seed)
indices = random.sample(range(n), k)
print(f"\nRandomly sampled {k} indices with seed={args.seed}: {indices}")
for idx in indices:
show_sample(df, idx, max_str_len=args.max_str_len)
if __name__ == "__main__":
main()