Skip to content

Commit b927e7e

Browse files
fineguyThe TensorFlow Datasets Authors
authored andcommitted
Move the logic to read the dataset info from the constructor to the info property.
PiperOrigin-RevId: 678619252
1 parent 2c45284 commit b927e7e

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tensorflow_datasets/core/dataset_builder.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,6 @@ def __init__(
289289
self._version = self._pick_version(version)
290290
# Compute the base directory (for download) and dataset/version directory.
291291
self._data_dir_root, self._data_dir = self._build_data_dir(data_dir)
292-
# If the dataset info is available, use it.
293-
if dataset_info.dataset_info_path(self.data_path).exists():
294-
self.info.read_from_directory(self._data_dir)
295-
else: # Use the code version (do not restore data)
296-
self.info.initialize_from_bucket()
297-
if self.BLOCKED_VERSIONS is not None:
298-
config_name = self._builder_config.name if self._builder_config else None
299-
if is_blocked := self.BLOCKED_VERSIONS.is_blocked(
300-
version=self._version, config=config_name
301-
):
302-
default_msg = (
303-
f"Dataset {self.name} is blocked at version {self._version} and"
304-
f" config {config_name}."
305-
)
306-
self.info.set_is_blocked(
307-
is_blocked.blocked_msg if is_blocked.blocked_msg else default_msg
308-
)
309292

310293
@utils.classproperty
311294
@classmethod
@@ -510,6 +493,23 @@ def info(self) -> dataset_info.DatasetInfo:
510493
"DatasetBuilder._info should returns `tfds.core.DatasetInfo`, not "
511494
f" {type(info)}."
512495
)
496+
# If the dataset info is available, use it.
497+
if dataset_info.dataset_info_path(self.data_path).exists():
498+
info.read_from_directory(self.data_path)
499+
else: # Use the code version (do not restore data)
500+
info.initialize_from_bucket()
501+
if self.BLOCKED_VERSIONS is not None:
502+
config_name = self._builder_config.name if self._builder_config else None
503+
if is_blocked := self.BLOCKED_VERSIONS.is_blocked(
504+
version=self._version, config=config_name
505+
):
506+
default_msg = (
507+
f"Dataset {self.name} is blocked at version {self._version} and"
508+
f" config {config_name}."
509+
)
510+
info.set_is_blocked(
511+
is_blocked.blocked_msg if is_blocked.blocked_msg else default_msg
512+
)
513513
return info
514514

515515
@utils.classproperty

tensorflow_datasets/core/dataset_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def read_from_directory(self, dataset_info_dir: epath.PathLike) -> None:
707707
)
708708

709709
self._identity = DatasetIdentity.from_proto(
710-
info_proto=parsed_proto, data_dir=dataset_info_dir
710+
info_proto=parsed_proto, data_dir=os.fspath(dataset_info_dir)
711711
)
712712

713713
# Update splits

0 commit comments

Comments
 (0)