Datasets:

Modalities:
Text
Languages:
code
ArXiv:
Libraries:
Datasets
License:
SeanNaren commited on
Commit
da5e8ef
1 Parent(s): 9ec7f28

gzip should be able to handle file handler

Browse files
Files changed (1) hide show
  1. code_clippy_github.py +25 -23
code_clippy_github.py CHANGED
@@ -175,29 +175,31 @@ class CodeClippyGithub(datasets.GeneratorBasedBuilder):
175
  def _generate_examples(self, files):
176
  key = 0
177
  for file_idx, file in enumerate(files):
178
- with xopen(file, "rb") as f:
179
- uncompressed_data = gzip.decompress(f.read())
180
-
181
- for batch_idx, code_base in enumerate(uncompressed_data):
182
- j_dict = json.loads(code_base.decode('utf-8'))
183
-
184
-
185
-
186
- lang = lang_from_name(j_dict['path'])
187
- license = j_dict["license"]
188
-
189
- if self.config.filter_languages and not lang in self.config.languages:
190
- continue
191
- if self.config.filter_licenses and not license in self.config.licenses:
192
- continue
193
- # TODO: Add more features like header comments, filename, and other features useful in a prompt.
194
- yield key, {"code_text": j_dict['content'],
195
- "repo_name": j_dict['repo_name'],
196
- "file_path": j_dict['path'],
197
- "license": license,
198
- "language": lang,
199
- "size": int(j_dict['f0_'])}
200
- key += 1
 
 
201
 
202
 
203
  def lang_from_name(name):
 
175
  def _generate_examples(self, files):
176
  key = 0
177
  for file_idx, file in enumerate(files):
178
+ with xopen(file, "rb") as file: # download file if in streaming mode
179
+ with gzip.open(file, "rb") as f:
180
+
181
+ uncompressed_data = f.readlines()
182
+
183
+ for batch_idx, code_base in enumerate(uncompressed_data):
184
+ j_dict = json.loads(code_base.decode('utf-8'))
185
+
186
+
187
+
188
+ lang = lang_from_name(j_dict['path'])
189
+ license = j_dict["license"]
190
+
191
+ if self.config.filter_languages and not lang in self.config.languages:
192
+ continue
193
+ if self.config.filter_licenses and not license in self.config.licenses:
194
+ continue
195
+ # TODO: Add more features like header comments, filename, and other features useful in a prompt.
196
+ yield key, {"code_text": j_dict['content'],
197
+ "repo_name": j_dict['repo_name'],
198
+ "file_path": j_dict['path'],
199
+ "license": license,
200
+ "language": lang,
201
+ "size": int(j_dict['f0_'])}
202
+ key += 1
203
 
204
 
205
  def lang_from_name(name):