lhoestq HF staff commited on
Commit
319b87e
1 Parent(s): 82a9037

Fix streaming mode & dataset viewer

Browse files

this should fix the dataset viewer by using streaming without overriding methodsthat can break the dataset viewer.

Files changed (1) hide show
  1. commavq.py +7 -13
commavq.py CHANGED
@@ -1,13 +1,12 @@
1
  import datasets
2
- import glob
3
  import os
4
  import numpy as np
5
 
6
  SHARD_SIZE = 2500
7
  NUM_SHARDS = 40
8
- _URLS = [
9
- f'https://huggingface.co/datasets/commaai/commavq/resolve/main/data_{i*SHARD_SIZE}_to_{(i+1)*SHARD_SIZE}.zip' for i in range(NUM_SHARDS)
10
- ] + [ f'https://huggingface.co/datasets/commaai/commavq/resolve/main/val.zip' ]
11
 
12
  _DESCRIPTION = """\
13
  TODO
@@ -26,7 +25,7 @@ class CommaVQ(datasets.GeneratorBasedBuilder):
26
  def _split_generators(self, dl_manager):
27
  """Returns SplitGenerators."""
28
  dl_manager.download_config.ignore_url_params = True
29
- downloaded_files = dl_manager.download(_URLS)
30
  local_extracted_archive = dl_manager.extract(downloaded_files) if not dl_manager.is_streaming else [None]*len(downloaded_files)
31
  return [
32
  datasets.SplitGenerator(
@@ -35,11 +34,6 @@ class CommaVQ(datasets.GeneratorBasedBuilder):
35
  ) for i in range(len(downloaded_files))]
36
 
37
  def _generate_examples(self, local_extracted_archive, files):
38
- files = glob.glob(os.path.join(local_extracted_archive, '*.npy'))
39
- for path in files:
40
- file_name = os.path.basename(path)
41
- yield file_name, {'path': path}
42
-
43
- def _get_examples_iterable_for_split(self, split_generator):
44
- for path in split_generator.gen_kwargs['files']:
45
- yield path[0], {'path': path[0]}
 
1
  import datasets
 
2
  import os
3
  import numpy as np
4
 
5
  SHARD_SIZE = 2500
6
  NUM_SHARDS = 40
7
+ _DATA_FILES = [
8
+ f'data_{i*SHARD_SIZE}_to_{(i+1)*SHARD_SIZE}.zip' for i in range(NUM_SHARDS)
9
+ ] + [ 'val.zip' ]
10
 
11
  _DESCRIPTION = """\
12
  TODO
 
25
  def _split_generators(self, dl_manager):
26
  """Returns SplitGenerators."""
27
  dl_manager.download_config.ignore_url_params = True
28
+ downloaded_files = dl_manager.download(_DATA_FILES)
29
  local_extracted_archive = dl_manager.extract(downloaded_files) if not dl_manager.is_streaming else [None]*len(downloaded_files)
30
  return [
31
  datasets.SplitGenerator(
 
34
  ) for i in range(len(downloaded_files))]
35
 
36
  def _generate_examples(self, local_extracted_archive, files):
37
+ for path_in_archive, f in files:
38
+ path = os.path.join(local_extracted_archive, path_in_archive) if local_extracted_archive is not None else path_in_archive
39
+ yield path_in_archive, {'path': path}