Skip to content

Commit a5d9682

Browse files
author
The TensorFlow Datasets Authors
committed
Internal change
PiperOrigin-RevId: 806185951
1 parent a4a0652 commit a5d9682

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

tensorflow_datasets/core/load.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
from collections.abc import Iterable, Iterator, Mapping, Sequence
21+
import contextlib # pylint: disable=unused-import
2122
import dataclasses
2223
import difflib
2324
import posixpath
@@ -657,12 +658,14 @@ def load(
657658
object documents the entire dataset, regardless of the `split` requested.
658659
Split-specific information is available in `ds_info.splits`.
659660
""" # fmt: skip
660-
dbuilder = _fetch_builder(
661-
name=name,
662-
data_dir=data_dir,
663-
builder_kwargs=builder_kwargs,
664-
try_gcs=try_gcs,
665-
)
661+
ctx = contextlib.nullcontext()
662+
with ctx:
663+
dbuilder = _fetch_builder(
664+
name=name,
665+
data_dir=data_dir,
666+
builder_kwargs=builder_kwargs,
667+
try_gcs=try_gcs,
668+
)
666669
_download_and_prepare_builder(dbuilder, download, download_and_prepare_kwargs)
667670

668671
if as_dataset_kwargs is None:
@@ -827,12 +830,10 @@ def data_source(
827830
""" # fmt:skip
828831
builder_kwargs = _set_file_format_for_data_source(data_dir, builder_kwargs)
829832
_validate_file_format_for_data_source(builder_kwargs)
830-
dbuilder = _fetch_builder(
831-
name,
832-
data_dir,
833-
builder_kwargs,
834-
try_gcs,
835-
)
833+
834+
ctx = contextlib.nullcontext()
835+
with ctx:
836+
dbuilder = _fetch_builder(name, data_dir, builder_kwargs, try_gcs)
836837
_download_and_prepare_builder(dbuilder, download, download_and_prepare_kwargs)
837838
return dbuilder.as_data_source(
838839
split=split, decoders=decoders, deserialize_method=deserialize_method

tensorflow_datasets/testing/dataset_builder_testing.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ def _test_checksums(self):
425425
f"Some urls checksums are missing at: {filepath}\n{err_msg}",
426426
)
427427

428-
def _download_and_prepare_as_dataset(self, builder):
428+
def _download_and_prepare_as_dataset(
429+
self,
430+
builder,
431+
):
429432
# Provide the manual dir only if builder has MANUAL_DOWNLOAD_INSTRUCTIONS
430433
# set.
431434

@@ -461,7 +464,9 @@ def _download_and_prepare_as_dataset(self, builder):
461464
beam_runner=beam_runner,
462465
)
463466
with self._test_key_not_local_path(builder):
464-
builder.download_and_prepare(download_config=download_config)
467+
builder.download_and_prepare(
468+
download_config=download_config,
469+
)
465470

466471
with self._subTest("as_dataset"):
467472
self._assertAsDataset(builder)

0 commit comments

Comments
 (0)