-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support for multiple input data objects in Syncopy decorators #47
Conversation
- the `unwrap_cfg` decorator has been extended to properly process not only single input data objects but arbitrary many (akin to MATLAB's `varargin`). Now, any function `func` decorated with `unwrap_cfg` can support (if wanted) things like ``func(data1, data2, data3, a="a", b=2)`` or equivalently ``dList = [data1, data2, data3]`` ``func(*dList, a="a", b=2)`` or equivalently using a `cfg` "structure" ``cfg.data = [data1, data2, data3]; cfg.a = "a"; cfg.b = 2`` ``func(cfg)`` - the "inner" decorator `unwrap_select` has been modified as well to expect `data` being a list, not a single Syncopy data object. If in-place selection is used w/multiple input objects, each object must be compatible w/the provided selection. - with an invasive modification like this, a dedicated test-suite seemed warranted, thus a new test file test_decorators.py has been added. Even for single-object tests, this might be a good idea anyway, to ease debugging w/complex algorithms (to faster determine if an error is rooted in a decorator or the algorithm) - todo: update docstrings in kwargs_decorators.py and fix a minor bug where a wrong `cfg` type triggers an `IndexError`, instead of the intended `SPYTypeError`. Changes to be committed: modified: syncopy/examples/ex_specest.py modified: syncopy/shared/kwarg_decorators.py new file: syncopy/tests/test_decorators.py
- fixed bug in `unwrap_cfg` that prevented `SPYTypeError` to be raised for non-dict-like `cfg` inputs - fixed a bug in `unwrap_cfg` that caused input objects provided as multiple positional args (`data1`, `data2`, ... or `*datalist`) to be propagated in reversed order (careless use of `pop()` instead of `pop(0)`). - changed logic of `unwrap_cfg`: do not propagate data objects encapsulated in a list but instead unfold the constructed `data` list by calling the decorated function using ``func(*data, *posargs, **kwargs)`` This way, `unwrap_cfg` does *not* change the type of `data` input objects (from Syncopy data to list). - changed `unwrap_select` following modifications of `unwrap_cfg`: cycle through anonymous `args` and attach `select` dictionary (if provided) to any object in `args` that has a `_selection` attribute. - changed `detect_parallel_client` following modifications of `unwrap_cfg`: use standard Python call signature `func(*args, **kwargs)` to invoke the wrapped function - updated docstrings of all decorators to reflect introduced changes Changes to be committed: modified: syncopy/shared/kwarg_decorators.py modified: syncopy/tests/test_decorators.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the the unwrap_cfg
decorator and am impressed by it's versatility (very clever how the docstring is manipulated).
If I understand the code correctly the wrapper also supports multiple positional data
arguments, i.e.
result = func(cfg, data1, data2, data3)
I did not see any documentation or tests for this use case. Is that right?
Yes, the documentation does not explicitly mention this use-case at the moment. This should be included in our developer docs (I'll open an issue addressing this). Regarding tests: the new testing module |
- instead of using `str(type(obj))` to check for Syncopy objects use the cleaner `isinstance`-approach instead (following the discussion in PR #47) Changes to be committed: modified: syncopy/shared/kwarg_decorators.py
Author Guidelines
new queuing system prevented me from starting afixed w/FIX: Repair SLURMClusters with Python execs in user homes #51SLURMCluster
in the 'DEV' queue - only tested w/LocalCluster
for nowReviewer Checklist