Skip to content
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

Column.get(map=) support dicts with partial keys #403

Merged
merged 2 commits into from
Nov 6, 2023

Conversation

hagenw
Copy link
Member

@hagenw hagenw commented Nov 6, 2023

This updates audformat.Column.get(map=) to only raise an error if the requested mapping scheme is not available in all dictionaries of the scheme labels and not just in some.

Let's start with:

import audformat

db = audformat.Database('db')
db.schemes['speaker'] = audformat.Scheme(
    'int',
    labels={
        0: {'age': 35, 'gender': 'female'},
        1: {'age': 26},
    },
)
db['files'] = audformat.Table(audformat.filewise_index(['f1', 'f2']))
db['files']['speaker'] = audformat.Column(scheme_id='speaker')
db['files']['speaker'].set([0, 1])

Now we get

>>> db['files']['speaker'].get(map='location')
...
ValueError: Cannot map 'speaker' to 'location'. Expected one of ['age', 'gender'].

but the following no longer raises an error

>>> db['files']['speaker'].get(map='gender')
file
f1    female
f2      <NA>
Name: gender, dtype: string

The text regarding when we raise a ValueError was not completely specific before:

image

so I would not call this a breaking change, but a bug fix.

Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Merging #403 (a832356) into main (5152318) will not change coverage.
The diff coverage is 100.0%.

Files Coverage Δ
audformat/core/column.py 100.0% <100.0%> (ø)

@hagenw hagenw requested a review from frankenjoe November 6, 2023 12:48
@frankenjoe frankenjoe merged commit 69332d4 into main Nov 6, 2023
10 checks passed
@frankenjoe frankenjoe deleted the column-get-map-fix branch November 6, 2023 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants