audeering / audformat

Format to store media files and annotations
https://audeering.github.io/audformat/
Other
11 stars 1 forks source link

utils.read_csv doesn't recognize format #420

Closed felixbur closed 6 months ago

felixbur commented 6 months ago

Hi, I want to read in the attached file train.csv

with

df = audformat.utils.read_csv(data_file)

but get back a Series, no error:

type(df)
<class 'pandas.core.series.Series'>

it works as expected with pandas.read_csv()

hagenw commented 6 months ago

If only one column is present in the data, it returns a series. You can convert to a dataframe with:

y = audformat.utils.read_csv("train.csv")
df = y.to_frame()

Or if it should be a dataframe independent of the number of columns:

obj = audformat.utils.read_csv("train.csv")
if isinstance(obj, pd.Series):
    df = obj.to_frame()
else:
    df = obj
hagenw commented 6 months ago

The current behavior is not written in the text of the corresponding docstring, but indicated by the return types:

image