Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion audformat/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def join_field(
for other in others:
for table_id in list(other.misc_tables) + list(other.tables):
table = other[table_id]
if table_id in self.tables:
if table_id in list(self):
self[table_id].update(table, overwrite=overwrite)
else:
self[table_id] = table.copy()
Expand Down
35 changes: 35 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,3 +963,38 @@ def test_update(tmpdir):
db.update(other1, overwrite=True, copy_attachments=True)
with pytest.raises(RuntimeError):
db.update(other1, overwrite=True, copy_media=True)


def test_update_misc_table():
"""Tests updating databases with misc tables.

This addresses the particular case
of adding a new column
to a misc table
in a database having only a single table,
which was failing as described in
https://github.com/audeering/audformat/issues/466

"""
db1 = audformat.Database("mydb")
db1.schemes["answer1"] = audformat.Scheme("str")
db1["sessions"] = audformat.MiscTable(pd.Index(["a"], name="session"))
db1["sessions"]["prompt_1"] = audformat.Column(scheme_id="answer1")
db1["sessions"]["prompt_1"].set(["response1"])
df1 = db1["sessions"].df.copy()

db2 = audformat.Database("mydb")
db2.schemes["answer1"] = audformat.Scheme("str")
db2.schemes["answer2"] = audformat.Scheme("str")
db2["sessions"] = audformat.MiscTable(pd.Index(["b"], name="session"))
db2["sessions"]["prompt_1"] = audformat.Column(scheme_id="answer1")
db2["sessions"]["prompt_2"] = audformat.Column(scheme_id="answer2")
db2["sessions"]["prompt_1"].set(["response1"])
db2["sessions"]["prompt_2"].set(["response2"])
df2 = db2["sessions"].df.copy()

df_expected = pd.concat([df1, df2])

db1.update(db2)
pd.testing.assert_frame_equal(db1["sessions"].df, df_expected)
pd.testing.assert_frame_equal(db2["sessions"].df, df2)