MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / stream_jsonl

Function stream_jsonl

eval/utils/data.py:15–29  ·  view source on GitHub ↗

Parses each jsonl line and yields it as a dictionary

(filename: str)

Source from the content-addressed store, hash-verified

13
14
15def stream_jsonl(filename: str) -> Iterable[Dict]:
16 """
17 Parses each jsonl line and yields it as a dictionary
18 """
19 if filename.endswith(".gz"):
20 with open(filename, "rb") as gzfp:
21 with gzip.open(gzfp, 'rt') as fp:
22 for line in fp:
23 if any(not x.isspace() for x in line):
24 yield json.loads(line)
25 else:
26 with open(filename, "r", encoding='utf-8') as fp:
27 for line in fp:
28 if any(not x.isspace() for x in line):
29 yield json.loads(line)
30
31
32def write_jsonl(filename: str, data: Iterable[Dict], append: bool = False):

Callers 4

combine_resultsFunction · 0.85
read_problemsFunction · 0.85
read_datasetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected