Skip to content

Commit 4aef4ae

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Override copy method in LazyMetadataDict
The standard implementation of copy results in an empty dict PiperOrigin-RevId: 696161577
1 parent bfd7c2e commit 4aef4ae

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tensorflow_datasets/core/dataset_info.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import abc
3636
from collections.abc import Iterable, Sequence
37+
import copy
3738
import dataclasses
3839
import json
3940
import os
@@ -1435,6 +1436,9 @@ def items(self):
14351436
self._load_metadata()
14361437
return super().items()
14371438

1439+
def copy(self):
1440+
return copy.deepcopy(self)
1441+
14381442

14391443
class BeamMetadataDict(MetadataDict):
14401444
"""A `tfds.core.Metadata` object supporting Beam-generated datasets."""

tensorflow_datasets/core/dataset_info_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,11 @@ def test_updating_before_loading(self, mock_load_metadata_from_file):
889889
metadata_dict.update({"abc": "def", "ghi": "jkl"})
890890
mock_load_metadata_from_file.assert_not_called()
891891

892+
def test_copy(self):
893+
metadata_dict = dataset_info.LazyMetadataDict(self.data_dir)
894+
metadata_dict_copy = metadata_dict.copy()
895+
self.assertEqual(metadata_dict_copy["test"], "test123")
896+
892897

893898
if __name__ == "__main__":
894899
testing.test_main()

0 commit comments

Comments
 (0)