docarray.array.mixins.io.csv module#

class docarray.array.mixins.io.csv.CsvIOMixin[source]#

Bases: object

CSV IO helper.

can be applied to DA & DAM

save_embeddings_csv(file, encoding='utf-8', **kwargs)[source]#

Save embeddings to a CSV file

This function utilizes numpy.savetxt() internal.

Parameters
  • file (Union[str, TextIO]) – File or filename to which the data is saved.

  • encoding (str) – encoding used to save the data into a file. By default, utf-8 is used.

  • kwargs – extra kwargs will be passed to numpy.savetxt().

Return type

None

save_csv(file, flatten_tags=True, exclude_fields=None, dialect='excel', with_header=True, encoding='utf-8')[source]#

Save array elements into a CSV file.

Parameters
  • file (Union[str, TextIO]) – File or filename to which the data is saved.

  • flatten_tags (bool) – if set, then all fields in Document.tags will be flattened into tag__fieldname and stored as separated columns. It is useful when tags contain a lot of information.

  • exclude_fields (Optional[Sequence[str]]) – if set, those fields wont show up in the output CSV

  • dialect (Union[str, Dialect]) – define a set of parameters specific to a particular CSV dialect. could be a string that represents predefined dialects in your system, or could be a csv.Dialect class that groups specific formatting parameters together.

  • encoding (str) – encoding used to save the data into a CSV file. By default, utf-8 is used.

Return type

None

classmethod load_csv(file, field_resolver=None, encoding='utf-8')[source]#

Load array elements from a binary file.

Parameters
  • file (Union[str, TextIO]) – File or filename to which the data is saved.

  • field_resolver (Optional[Dict[str, str]]) – a map from field names defined in JSON, dict to the field names defined in Document.

  • encoding (str) – encoding used to read a CSV file. By default, utf-8 is used.

Return type

T

Returns

a DocumentArray object