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 table as CSV text, optionally writing it to a path.

Reached as annotation_set.io.to_csv.

A bare table holds only annotations, so a set with features beyond the groups its feature_id column implies, or with bases, is written with save instead. A duration dimension is refused: CSV has no spelling for one which reads back, where parquet has a type for it.

The dimensions are not written. Reading the 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(
    {"phase": ["P"], "distance_min": [10.0], "distance_max": [80.0]}
)
annotations = dc.AnnotationSet(frame, dims=("time", "distance"))
"phase" in annotations.io.to_csv()
True