audeering / audobject

Generic Python interface for serializing objects to YAML
https://audeering.github.io/audobject/
Other
1 stars 0 forks source link

Move static Object functions to module level? #15

Closed hagenw closed 3 years ago

hagenw commented 3 years ago

If a user does something like:

transform = audsp.Spectrogram(...)
transform.to_yaml('transform.yaml')

it is obvious what will happen.

But to load the transform the user can do:

audobject.Object.from_yaml('transform.yaml')
audsp.Spectrogram.from_yaml('transform.yaml')
audsp.Cepstrogram.from_yaml('transform.yaml')

which all return

{'$audsp.core.spectrogram.Spectrogram': {'win_dur': 0.2, 'hop_dur': 0.1, 'power': False, 'num_fft': 4096, 'center': False, 'reflect': False, 'zero_phase': False, 'audspec': None, 'unit': 'seconds', 'channels': [0], 'mixdown': False, 'resample': False, 'sampling_rate': 16000}}

Especially audsp.Cepstrogram.from_yaml('transform.yaml') is very misleading.

I would propose that me move the static functions

Or maybe add a load, e.g. audobject.load_from_dict(), ...

In the above example the code would then read:

audobject.from_yaml('transform')

and this is the only way to load the transform. The only downside is that the user has to import audobject on top/instead of audsp.

frankenjoe commented 3 years ago

I like your proposal as it indeed provides a cleaner API.