MCPcopy Create free account
hub / github.com/tensorflow/datasets / _write_index_file

Function _write_index_file

tensorflow_datasets/core/writer.py:159–178  ·  view source on GitHub ↗

Writes index file for records of a shard at given `sharded_index_path`. NOTE: Each record position (i.e shard_key in shard_keys) is stored as a string for better readability of the index files. The reader should parse the position from string using `RecordPosition.from_str()` method. Args:

(
    sharded_index_path: epath.PathLike, record_keys: Sequence[Any]
)

Source from the content-addressed store, hash-verified

157
158
159def _write_index_file(
160 sharded_index_path: epath.PathLike, record_keys: Sequence[Any]
161):
162 """Writes index file for records of a shard at given `sharded_index_path`.
163
164 NOTE: Each record position (i.e shard_key in shard_keys) is stored as a
165 string for better readability of the index files. The reader should parse the
166 position from string using `RecordPosition.from_str()` method.
167
168 Args:
169 sharded_index_path: Path to the sharded index path.
170 record_keys: Sequence of keys/indices of the records in the shard.
171 """
172 # Store string representation of each record position.
173 #
174 # NOTE: This makes the index file more readable. Although the reader should
175 # parse the record position from a string.
176 index_info = {"index": [str(record_key) for record_key in record_keys]}
177 epath.Path(sharded_index_path).write_text(json.dumps(index_info))
178 logging.info("Wrote index file to %s", os.fspath(sharded_index_path))
179
180
181class ExampleWriter:

Callers 2

finalizeMethod · 0.85
_write_final_shardMethod · 0.85

Calls 1

infoMethod · 0.45

Tested by

no test coverage detected