-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load additional schemes for segments in audformat.Database.get()
from filewise table
#460
Comments
Great observation, seems I have relied too much on |
I had a look at the unittests, which test a lot of cases: audformat/tests/test_database_get.py Lines 289 to 640 in 4fd2ae1
Which do indeed miss your case. Which might explain why we haven't found the bug before. |
I was able to add a test case that covers your described case at #461, which is indeed failing as it returns
|
An example, to clarify the expected behavior. import audformat
db = audformat.Database("mydb")
db.schemes["label1"] = audformat.Scheme("str")
db.schemes["label2"] = audformat.Scheme("int")
files = audformat.filewise_index(["f1", "f2"])
segments = audformat.segmented_index(["f1", "f1", "f2", "f2"], [0, 1, 0, 1], [1, 2, 1, 2])
db["files"] = audformat.Table(files)
db["files"]["label1"] = audformat.Column(scheme_id="label1")
db["files"]["label1"].set(["a", "b"])
db["segments"] = audformat.Table(segments)
db["segments"]["label2"] = audformat.Column(scheme_id="label2")
db["segments"]["label2"].set([0, 1, 2, 3]) Which means we have: >>> db["files"].df
label1
file
f1 a
f2 b
>>> db["segments"].df
label2
file start end
f1 0 days 00:00:00 0 days 00:00:01 0
0 days 00:00:01 0 days 00:00:02 1
f2 0 days 00:00:00 0 days 00:00:01 2
0 days 00:00:01 0 days 00:00:02 3 We can request the scheme stored in the filewise table as the main scheme, and the scheme stored in the segmented table as additional annotations. As we cannot merge them easily together all the time, we return the filewise and segmented labels in different rows: >>> db.get("label1", additional_schemes="label2")
label1 label2
file start end
f1 0 days 00:00:00 NaT a <NA>
0 days 00:00:01 <NA> 0
0 days 00:00:01 0 days 00:00:02 <NA> 1
f2 0 days 00:00:00 NaT b <NA>
0 days 00:00:01 <NA> 2
0 days 00:00:01 0 days 00:00:02 <NA> 3 When starting with the scheme stored as segments as the main scheme, and adding an scheme stored in a filewise table as additional scheme, I would expect it should return the following as we can clearly map the filewise label to every segment (topic of this issue): >>> db.get("label2", additional_schemes="label1")
label2 label1
file start end
f1 0 days 00:00:00 0 days 00:00:01 0 a
0 days 00:00:01 0 days 00:00:02 1 a
f2 0 days 00:00:00 0 days 00:00:01 2 b
0 days 00:00:01 0 days 00:00:02 3 b An alternative approach would be to be in line with the behavior of the first example, and not merge the rows together: >>> db.get("label2", additional_schemes="label1")
label2 label1
file start end
f1 0 days 00:00:00 NaT <NA> a
0 days 00:00:01 0 <NA>
0 days 00:00:01 0 days 00:00:02 1 <NA>
f2 0 days 00:00:00 NaT <NA> b
0 days 00:00:01 2 <NA>
0 days 00:00:01 0 days 00:00:02 3 <NA> I as a user would prefer to return the values in the way of the first solution and merge the entries together. |
For a database
db
with a segment-wise table with a columncol_1
and a filewise table with a columnmeta_1
,db.get("col_1", additional_schemes="meta_1")
doesn't load the column data frommeta_1
from the filewise table:The text was updated successfully, but these errors were encountered: