is_index_alike()

audformat.utils.is_index_alike(objs)[source]

Check if index objects are alike.

Two index objects are alike if they have the same number of levels and share the same level names. In addition, the dtypes have to match the the same audformat dtypes category, compare audformat.define.DataType.

Parameters

objs (Sequence[Union[Index, Series, DataFrame]]) – objects

Return type

bool

Returns

True if index objects are alike, otherwise False

Examples

>>> index1 = pd.Index([1, 2, 3], dtype="Int64", name="l")
>>> index2 = pd.MultiIndex.from_arrays([[10, 20]], names=["l"])
>>> is_index_alike([index1, index2])
True
>>> is_index_alike([index1, pd.Series(["a", "b"], index=index2)])
True
>>> index3 = index2.set_names(["L"])
>>> is_index_alike([index2, index3])
False
>>> index4 = index2.set_levels([["10", "20"]])
>>> is_index_alike([index2, index4])
False
>>> index5 = pd.MultiIndex.from_arrays([[1], ["a"]], names=["l1", "l2"])
>>> is_index_alike([index2, index5])
False
>>> index6 = pd.MultiIndex.from_arrays([["a"], [1]], names=["l2", "l1"])
>>> is_index_alike([index5, index6])
False