Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 33 additions & 51 deletions tests/test_misc_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ def create_misc_table(
create_misc_table(
pd.Series(
[1.0],
index=pd.Index(["a"], name="idx"),
index=pd.Index(["a"], name="idx", dtype="object"),
),
),
create_misc_table(
pd.Series(
index=pd.Index([], name="idx"),
index=pd.Index([], name="idx", dtype="object"),
dtype="float",
),
),
],
create_misc_table(
pd.Series(
[1.0],
index=pd.Index(["a"], name="idx"),
index=pd.Index(["a"], name="idx", dtype="object"),
),
),
),
Expand All @@ -127,21 +127,21 @@ def create_misc_table(
[
create_misc_table(
pd.Series(
index=pd.Index([], name="idx"),
index=pd.Index([], name="idx", dtype="string"),
dtype="float",
)
),
create_misc_table(
pd.Series(
[1.0],
index=pd.Index(["a"], name="idx"),
index=pd.Index(["a"], name="idx", dtype="string"),
),
),
],
create_misc_table(
pd.Series(
[1.0],
index=pd.Index(["a"], name="idx"),
index=pd.Index(["a"], name="idx", dtype="string"),
),
),
),
Expand Down Expand Up @@ -512,14 +512,14 @@ def test_dtype_column(
(
pd.Index,
["0"],
None,
"object",
"object",
audformat.define.DataType.OBJECT,
),
(
pd.Index,
[],
None,
"object",
"object",
audformat.define.DataType.OBJECT,
),
Expand Down Expand Up @@ -572,13 +572,6 @@ def test_dtype_column(
"Int64",
audformat.define.DataType.INTEGER,
),
(
pd.Index,
[],
str,
"object",
audformat.define.DataType.OBJECT,
),
(
pd.Index,
[],
Expand Down Expand Up @@ -638,7 +631,7 @@ def test_dtype_column(
(
pd.Index,
["0"],
None,
"object",
"object",
audformat.define.DataType.OBJECT,
),
Expand Down Expand Up @@ -780,12 +773,6 @@ def test_dtype_index(
"Int64",
audformat.define.DataType.INTEGER,
),
(
[],
str,
"object",
audformat.define.DataType.OBJECT,
),
(
[],
"string",
Expand Down Expand Up @@ -836,7 +823,7 @@ def test_dtype_index(
),
(
["0"],
None,
"object",
"object",
audformat.define.DataType.OBJECT,
),
Expand Down Expand Up @@ -964,12 +951,6 @@ def test_dtype_multiindex(
"Int64",
audformat.define.DataType.INTEGER,
),
(
[],
str,
"object",
audformat.define.DataType.OBJECT,
),
(
[],
"string",
Expand Down Expand Up @@ -1020,7 +1001,7 @@ def test_dtype_multiindex(
),
(
["0"],
None,
"object",
"object",
audformat.define.DataType.OBJECT,
),
Expand Down Expand Up @@ -1157,20 +1138,20 @@ def test_drop_extend_and_pick_index_order():
# table empty
(
create_misc_table(pd.Index([], name="idx")),
pd.Index(["a", "b"], name="idx"),
pd.Index(["a", "b"], name="idx", dtype="object"),
pd.Index([], name="idx"),
),
# index empty
(
create_misc_table(pd.Index(["a", "b"], name="idx")),
pd.Index([], name="idx"),
pd.Index(["a", "b"], name="idx"),
create_misc_table(pd.Index(["a", "b"], name="idx", dtype="string")),
pd.Index([], name="idx", dtype="string"),
pd.Index(["a", "b"], name="idx", dtype="string"),
),
# index and table identical
(
create_misc_table(pd.Index(["a", "b"], name="idx")),
pd.Index(["b", "a"], name="idx"),
pd.Index([], name="idx"),
create_misc_table(pd.Index(["a", "b"], name="idx", dtype="string")),
pd.Index(["b", "a"], name="idx", dtype="string"),
pd.Index([], name="idx", dtype="string"),
),
# index within table
(
Expand All @@ -1180,9 +1161,9 @@ def test_drop_extend_and_pick_index_order():
),
# table within index
(
create_misc_table(pd.Index(["b"], name="idx")),
pd.Index(["a", "b"], name="idx"),
pd.Index([], name="idx"),
create_misc_table(pd.Index(["b"], name="idx", dtype="string")),
pd.Index(["a", "b"], name="idx", dtype="string"),
pd.Index([], name="idx", dtype="string"),
),
# index and table overlap
(
Expand Down Expand Up @@ -1221,30 +1202,30 @@ def test_extend_index():
# empty and invalid

db["misc"] = audformat.MiscTable(pd.Index([], name="idx"))
db["misc"].extend_index(pd.Index([], name="idx"))
db["misc"].extend_index(pd.Index([], name="idx", dtype="object"))
assert db["misc"].get().empty
with pytest.raises(
ValueError,
match="Cannot extend",
):
db["misc"].extend_index(pd.Index([], name="other"))
db["misc"].extend_index(pd.Index([], name="other", dtype="object"))

db.drop_tables("misc")

# extend with pd.Index

db["misc"] = audformat.MiscTable(pd.Index([], name="idx"))
db["misc"] = audformat.MiscTable(pd.Index([], name="idx", dtype="object"))
db["misc"]["columns"] = audformat.Column(scheme_id="scheme")
db["misc"].extend_index(
pd.Index(["1", "2"], name="idx"),
pd.Index(["1", "2"], name="idx", dtype="object"),
fill_values="a",
inplace=True,
)
np.testing.assert_equal(
db["misc"]["columns"].get().values,
np.array(["a", "a"]),
)
index = pd.Index(["1", "3"], name="idx")
index = pd.Index(["1", "3"], name="idx", dtype="object")
db["misc"].extend_index(
index,
fill_values="b",
Expand All @@ -1258,6 +1239,7 @@ def test_extend_index():
# extend with pd.MultiIndex

index = pd.MultiIndex.from_arrays([["1", "4"]], names=["idx"])
index = audformat.utils.set_index_dtypes(index, "object")
db["misc"].extend_index(
index,
fill_values="b",
Expand Down Expand Up @@ -1391,15 +1373,15 @@ def test_load_old_pickle(tmpdir):
),
# table empty
(
create_misc_table(pd.Index([], name="idx")),
pd.Index(["a", "b"], name="idx"),
pd.Index([], name="idx"),
create_misc_table(pd.Index([], name="idx", dtype="object")),
pd.Index(["a", "b"], name="idx", dtype="object"),
pd.Index([], name="idx", dtype="object"),
),
# index empty
(
create_misc_table(pd.Index(["a", "b"], name="idx")),
pd.Index([], name="idx"),
pd.Index([], name="idx"),
create_misc_table(pd.Index(["a", "b"], name="idx", dtype="object")),
pd.Index([], name="idx", dtype="object"),
pd.Index([], name="idx", dtype="object"),
),
# index and table identical
(
Expand Down