MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / stream_jsonl

Function stream_jsonl

codegeex/data/data_utils.py:67–81  ·  view source on GitHub ↗

Parses each jsonl line and yields it as a dictionary

(filename: str)

Source from the content-addressed store, hash-verified

65
66
67def stream_jsonl(filename: str) -> Iterable[Dict]:
68 """
69 Parses each jsonl line and yields it as a dictionary
70 """
71 if filename.endswith(".gz"):
72 with open(filename, "rb") as gzfp:
73 with gzip.open(gzfp, "rt") as fp:
74 for line in fp:
75 if any(not x.isspace() for x in line):
76 yield json.loads(line)
77 else:
78 with open(filename, "r") as fp:
79 for line in fp:
80 if any(not x.isspace() for x in line):
81 yield json.loads(line)
82
83
84def write_jsonl(filename: str, data: Iterable[Dict], append: bool = False):

Callers 3

read_datasetFunction · 0.90
read_translation_datasetFunction · 0.90
load_pretrain_datasetFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected