Skip to content

Empty misc table can lead to errors #432

@hagenw

Description

@hagenw

One can initialize a misc table with None as index:

>>> import audformat
>>> table = audformat.MiscTable(None)

But this let's some of its method fail:

>>> table.copy()
...
ValueError: Got index with levels [None], but names must be non-empty and unique.

>>> table.extend_index(pd.Index([0, 1, 2], name="idx"))
...
ValueError: Got index with levels [None], but names must be non-empty and unique.

>>> table.extend_index(pd.Index([0, 1, 2], name="idx"), inplace=True)
ValueError: Cannot extend table if input index and table index are not alike.
Expected index:
        idx    int64
but yours is:
        None    int64

You can extend the table with:

>>> table.extend_index(pd.Index([0, 1, 2]), inplace=True)
>>> table.index
Index([0, 1, 2], dtype='Int64')

But now you have created a table without a name for the index and empty levels:

>>> table.levels

If you would have tried this when creating the table, it would have failed with

>>> table = audformat.MiscTable(pd.Index([0, 1, 2]))
...
ValueError: Got index with levels [None], but names must be non-empty and unique.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions