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

Add per execution process_func_args argument #157

Merged
merged 10 commits into from
Mar 21, 2024

Conversation

hagenw
Copy link
Member

@hagenw hagenw commented Jan 26, 2024

Closes #156

This adds a process_func_args argument to all the processing methods, e.g. audinterface.Process.process_index().
It can be used to overwrite the process_func_args argument used during instantiation of the interface.

Example:

import audinterface
import numpy as np

def addition(signal, sampling_rate, value=1):
    return signal + value * signal

interface = audinterface.Process(
    process_func=addition,
    process_func_args={"value": 2},
)
signal = np.ones((1, 3))
sampling_rate = 8000
interface.process_signal(signal, sampling_rate, process_func_args={"value": 3})

returns

start   end                   
0 days  0 days 00:00:00.000375    [[4.0, 4.0, 4.0]]
dtype: object

It will not overwrite the content of the class attribute interface.process_func_args, which will always only store the global setting.

Example docstring:

image

@hagenw hagenw marked this pull request as draft January 26, 2024 12:55
Copy link

codecov bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.0%. Comparing base (31ad344) to head (7d0b16e).
Report is 2 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
audinterface/core/feature.py 100.0% <100.0%> (ø)
audinterface/core/process.py 100.0% <100.0%> (ø)
audinterface/core/process_with_context.py 100.0% <100.0%> (ø)
audinterface/core/segment.py 100.0% <100.0%> (ø)

@hagenw hagenw changed the title Add process_func_args argument to process_*() methods Add per execution process_func_args argument Mar 21, 2024
@hagenw hagenw marked this pull request as ready for review March 21, 2024 11:55
@hagenw hagenw requested a review from maxschmitt March 21, 2024 11:55
Copy link
Contributor

@maxschmitt maxschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feature and the extensive new tests.
Looks good to me.

@hagenw hagenw merged commit d10bb27 into main Mar 21, 2024
16 checks passed
@hagenw hagenw deleted the add-process_func_args-to-process-funcs branch March 21, 2024 12:59
Comment on lines -174 to +176
# figure out if special arguments
# to pass to the processing function
signature = inspect.signature(process_func)
process_func_args = process_func_args or {}
self._process_func_special_args = {
'idx': False,
'root': False,
'file': False,
}
for key in self._process_func_special_args:
if (
key in signature.parameters
and key not in process_func_args
):
self._process_func_special_args[key] = True
self._process_func_signature = signature.parameters
r"""Arguments present in processing function."""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankenjoe

If you are curious, I think this might be the only change in audinterface 1.2.0, that touches attributes of the objects.

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.

Suggested feature: process_func_args in process_index()etc.
2 participants