tfds.file_adapter.CSVAdapter

Class CSVAdapter

Inherits From: FileFormatAdapter

Defined in core/file_format_adapter.py.

Writes/reads features to/from CSV files.

Constraints on generators:

  • The generator must yield feature dictionaries (dict<str feature_name, feature_value>).
  • The allowed feature types are int, float, and str. By default, only scalar features are supported (that is, not lists).

You can modify how records are written by passing csv_writer_ctor.

You can modify how records are read by passing csv_dataset_kwargs.

Note that all CSV files produced will have a header row.

__init__

__init__(
    feature_types,
    csv_dataset_kwargs=None,
    csv_writer_ctor=csv.writer
)

Constructs CSVAdapter.

Args:

feature_types (dict): specifies the dtypes of each of the features (columns in the CSV file). csv_dataset_kwargs (dict): forwarded to tf.data.experimental.CsvDataset. csv_writer_ctor (function): takes file handle and returns writer.

Raises:

  • ValueError: if csv_dataset_kwargs["header"] is present.

Properties

filetype_suffix

Methods

dataset_from_filename

dataset_from_filename(filename)

write_from_generator

write_from_generator(
    generator_fn,
    output_files
)