albertvillanova HF staff commited on
Commit
86f88c0
1 Parent(s): efe2c92

Remove apache_beam import from module level in natural_questions dataset (#4780)

Browse files

Move apache_beam dependency in natural_questions to method _build_pcollection

Commit from https://github.com/huggingface/datasets/commit/63205e1500fc9977f8e804a8858ffe7f594e59bf

Files changed (1) hide show
  1. natural_questions.py +6 -2
natural_questions.py CHANGED
@@ -21,8 +21,6 @@ import html
21
  import json
22
  import re
23
 
24
- import apache_beam as beam
25
-
26
  import datasets
27
 
28
 
@@ -145,6 +143,12 @@ class NaturalQuestions(datasets.BeamBasedBuilder):
145
 
146
  def _build_pcollection(self, pipeline, filepaths):
147
  """Build PCollection of examples."""
 
 
 
 
 
 
148
 
149
  def _parse_example(line):
150
  """Parse a single json line and emit an example dict."""
21
  import json
22
  import re
23
 
 
 
24
  import datasets
25
 
26
 
143
 
144
  def _build_pcollection(self, pipeline, filepaths):
145
  """Build PCollection of examples."""
146
+ try:
147
+ import apache_beam as beam
148
+ except ImportError as err:
149
+ raise ImportError(
150
+ "To be able to load natural_questions, you need to install apache_beam: 'pip install apache_beam'"
151
+ ) from err
152
 
153
  def _parse_example(line):
154
  """Parse a single json line and emit an example dict."""