annotation_set_to_csv

function of dascore.core.annotations source

annotation_set_to_csv(
    annotations: AnnotationSet ,
    path: str | pathlib._local.Path | None[str, Path, None] = None,
)-> ‘str’

Return the annotations as CSV text, optionally writing it to a path.

Reached as annotation_set.io.to_csv.

A bare table states one grain, so a set holding vertices is written with save instead; this is the spelling for a set of regions. A duration dimension is refused: a CSV has no spelling for one which reads back, where parquet has a type for it.

The dimensions are not written: they are not a column, and the only place a CSV has for them is a comment line, which a reader not told to expect one takes for the header. Reading such a table back states them again, in the call or in a # dims: distance, time line written above the header by hand.

Parameters

Parameter Description
annotations The set to write.
path Where to write the text, or None to only return it.

Examples

import pandas as pd
import dascore as dc
frame = pd.DataFrame(
    {"group": ["event"], "distance_min": [10.0], "distance_max": [80.0]}
)
annotations = dc.AnnotationSet(frame, dims=("time", "distance"))
"group" in annotations.io.to_csv()
True