[go: nahoru, domu]

Skip to content

Commit

Permalink
Silence some pytype errors.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 516481032
  • Loading branch information
rchen152 authored and The TensorFlow Datasets Authors committed Mar 14, 2023
1 parent ab96f21 commit d21fd25
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ConllDatasetBuilder(
@property
def builder_config(self) -> ConllBuilderConfig:
"""`tfds.core.BuilderConfig` for this builder."""
return self._builder_config
return self._builder_config # pytype: disable=bad-return-type # always-use-return-annotations

def create_dataset_info(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ConllUDatasetBuilder(
@property
def builder_config(self) -> ConllUBuilderConfig:
"""`tfds.core.BuilderConfig` for this builder."""
return self._builder_config
return self._builder_config # pytype: disable=bad-return-type # always-use-return-annotations

def create_dataset_info(
self,
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_datasets/datasets/anli/anli_dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _split_generators(self, dl_manager):
"filepath": os.path.join(
dl_dir,
EXTRACT_PATH_TOKEN,
self._builder_config.round_dir,
self._builder_config.round_dir, # pytype: disable=attribute-error # always-use-return-annotations
"test.jsonl",
)
},
Expand All @@ -98,7 +98,7 @@ def _split_generators(self, dl_manager):
"filepath": os.path.join(
dl_dir,
EXTRACT_PATH_TOKEN,
self._builder_config.round_dir,
self._builder_config.round_dir, # pytype: disable=attribute-error # always-use-return-annotations
"dev.jsonl",
)
},
Expand All @@ -109,7 +109,7 @@ def _split_generators(self, dl_manager):
"filepath": os.path.join(
dl_dir,
EXTRACT_PATH_TOKEN,
self._builder_config.round_dir,
self._builder_config.round_dir, # pytype: disable=attribute-error # always-use-return-annotations
"train.jsonl",
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _info(self) -> tfds.core.DatasetInfo:

def _split_generators(self, dl_manager: tfds.download.DownloadManager):
"""Returns SplitGenerators."""
granularity = self._builder_config.granularity
granularity = self._builder_config.granularity # pytype: disable=attribute-error # always-use-return-annotations
alignments_base_path = os.path.join(
dl_manager.manual_dir,
"booksum",
Expand Down
10 changes: 5 additions & 5 deletions tensorflow_datasets/datasets/groove/groove_dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _split_generators(self, dl_manager):
data_dir = os.path.join(
dl_manager.download_and_extract(
_DOWNLOAD_URL
if self._builder_config.include_audio
if self._builder_config.include_audio # pytype: disable=attribute-error # always-use-return-annotations
else _DOWNLOAD_URL_MIDI_ONLY
),
"groove",
Expand All @@ -165,21 +165,21 @@ def _split_generators(self, dl_manager):
]

def _generate_examples(self, rows, data_dir):
split_bars = self._builder_config.split_bars
split_bars = self._builder_config.split_bars # pytype: disable=attribute-error # always-use-return-annotations
for row in rows:
split_genre = row["style"].split("/")
with tf.io.gfile.GFile(
os.path.join(data_dir, row["midi_filename"]), "rb"
) as midi_f:
midi = midi_f.read()
audio = None
if self._builder_config.include_audio:
if self._builder_config.include_audio: # pytype: disable=attribute-error # always-use-return-annotations
if not row["audio_filename"]:
# Skip examples with no audio.
logging.warning("Skipping example with no audio: %s", row["id"])
continue
wav_path = os.path.join(data_dir, row["audio_filename"])
audio = _load_wav(wav_path, self._builder_config.audio_rate)
audio = _load_wav(wav_path, self._builder_config.audio_rate) # pytype: disable=attribute-error # always-use-return-annotations

example = {
"id": row["id"],
Expand All @@ -203,7 +203,7 @@ def _generate_examples(self, rows, data_dir):
bpm = int(row["bpm"])
beats_per_bar = int(row["time_signature"].split("-")[0])
bar_duration = 60 / bpm * beats_per_bar
audio_rate = self._builder_config.audio_rate
audio_rate = self._builder_config.audio_rate # pytype: disable=attribute-error # always-use-return-annotations

pm = tfds.core.lazy_imports.pretty_midi.PrettyMIDI(io.BytesIO(midi))
total_duration = pm.get_end_time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Builder(tfds.core.GeneratorBasedBuilder):

def _info(self):
# Should return a tfds.core.DatasetInfo object
if self._builder_config.recap_source == 'fd':
if self._builder_config.recap_source == 'fd': # pytype: disable=attribute-error # always-use-return-annotations
features = tfds.features.FeaturesDict({
_TRANSCRIPT: tfds.features.Text(),
_RECAP: tfds.features.Text(),
Expand All @@ -124,7 +124,7 @@ def _info(self):
'show_title': tfds.features.Text(),
'transcript_author': tfds.features.Text(),
})
elif self._builder_config.recap_source == 'tms':
elif self._builder_config.recap_source == 'tms': # pytype: disable=attribute-error # always-use-return-annotations
features = tfds.features.FeaturesDict({
_TRANSCRIPT: tfds.features.Text(),
_RECAP: tfds.features.Text(),
Expand All @@ -137,7 +137,7 @@ def _info(self):
})
else:
raise KeyError(
f'Unknown recap_source {self._builder_config.recap_source}'
f'Unknown recap_source {self._builder_config.recap_source}' # pytype: disable=attribute-error # always-use-return-annotations
)

return self.dataset_info_from_configs(
Expand All @@ -150,11 +150,11 @@ def _split_generators(self, dl_manager):
dl_paths = dl_manager.download_and_extract(_DL_URLS)
filenames_dict = _get_filenames_dict(
tokenized_path=dl_paths['tokenized'],
recap_source=self._builder_config.recap_source,
recap_source=self._builder_config.recap_source, # pytype: disable=attribute-error # always-use-return-annotations
)
paths_dict = _get_paths_dict(
untokenized_path=dl_paths['untokenized'],
recap_source=self._builder_config.recap_source,
recap_source=self._builder_config.recap_source, # pytype: disable=attribute-error # always-use-return-annotations
filenames_dict=filenames_dict,
)
return {
Expand All @@ -167,7 +167,7 @@ def _generate_examples(self, paths):
for path in paths:
example = _load_json(path)
fname = os.path.basename(path)
if self._builder_config.recap_source == 'fd':
if self._builder_config.recap_source == 'fd': # pytype: disable=attribute-error # always-use-return-annotations
yield fname, {
_TRANSCRIPT: '\n'.join(example['Transcript']),
_RECAP: '\n'.join(example['Recap']),
Expand All @@ -176,7 +176,7 @@ def _generate_examples(self, paths):
'show_title': example['Show Title'],
'transcript_author': example['Transcript Author'],
}
elif self._builder_config.recap_source == 'tms':
elif self._builder_config.recap_source == 'tms': # pytype: disable=attribute-error # always-use-return-annotations
yield fname, {
_TRANSCRIPT: '\n'.join(example['Transcript']),
_RECAP: '\n'.join(example['Recap']),
Expand All @@ -187,5 +187,5 @@ def _generate_examples(self, paths):
}
else:
raise KeyError(
f'Unknown recap_source {self._builder_config.recap_source}'
f'Unknown recap_source {self._builder_config.recap_source}' # pytype: disable=attribute-error # always-use-return-annotations
)

0 comments on commit d21fd25

Please sign in to comment.