Support keyword-only parameters and default values in decorated functions #31
Support keyword-only parameters and default values in decorated functions #31bastianhagedorn wants to merge 6 commits intomainfrom
Conversation
len(sig.parameters) includes VAR_KEYWORD (**kwargs) and VAR_POSITIONAL (*args) parameters, causing _sanitize_configs and run_profile_session to reject valid configs with a spurious argument count mismatch error. Fixed in 4 locations: - core.py: _sanitize_configs (2 places) - core.py: run_profile_session - transformation.py: transform_df - extraction.py: arg_arrays creation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add notes to core_concepts.rst, known_issues.rst, and the _sanitize_configs docstring clarifying that configs are passed as positional args only — *args and **kwargs in the function signature are tolerated but always empty during profiling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Keyword-only parameters (after * or *args) will fail at runtime since configs are passed via func(*config). Update docs to be precise about what parameter kinds are supported vs tolerated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add _bind_config_to_signature to map config values to both positional and keyword-only parameters in declaration order - Add _get_regular_params and _count_params helpers to exclude *args/**kwargs - Add test_function_with_keyword_only_params, test_function_with_args_and_keyword_only, and test_too_many_config_args_rejected - Update docs: keyword-only params are now supported, *args/**kwargs tolerated, default values still require explicit config values Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When configs provide fewer values than the function has parameters, _sanitize_configs pads the configs with default values from the function signature. This ensures the full pipeline (ncu subprocess, extraction, transformation) always sees full-length configs. Also fixes two pre-existing issues exposed by None defaults: - transformation.py: Value column stays object dtype after explode, now explicitly converted to numeric before aggregation - transformation.py: groupby now uses dropna=False to handle None/NaN values in function parameter columns Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove errors="coerce" from pd.to_numeric so non-numeric values raise an error instead of being silently converted to NaN. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bastianhagedorn, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/ |
|
/ok to test 19e7f56 |
|
Shame we can't support *args and **kwargs. This is just because there is no way to map a config tuple to *args and **kwargs right? Maybe we could improve this in a follow up MR. Instead of just passing configs as simple tuples, we could pass a For example something like this: The arguments passed to the And to maintain backwards compatibility, |
Fix
**kwargshandling and support keyword-only params and default valuesProblem
_sanitize_configsandrun_profile_sessionusedlen(sig.parameters)to count function parameters, which includes*argsand**kwargs. This caused a spurious validation error when the decorated function had**kwargsin its signature. Keyword-only parameters (after*) were also unsupported since configs were passed viafunc(*c)which can't populate keyword-only args.Additionally, parameters with default values could not be omitted from configs — users had to always provide values for every parameter, even those with sensible defaults.
Fix
**kwargs/*argshandling: ExcludeVAR_POSITIONALandVAR_KEYWORDparameters from all parameter counting and config validation (4 locations acrosscore.py,extraction.py,transformation.py)._bind_config_to_signaturehelper maps config values to parameters in declaration order, passing keyword-only params as**kwargsto the function call._pad_config_with_defaultsfills in missing trailing config values with defaults from the function signature. This happens in_sanitize_configsso the rest of the pipeline always sees full-length configs.Valuecolumn is now explicitly cast to numeric after explode (was staying asobjectdtype), andgroupbyusesdropna=Falseto handleNone/NaNdefault values in parameter columns.Tests
test_function_with_kwargs—**kwargstolerated in signaturetest_function_with_keyword_only_params—def f(x, *, y)workstest_function_with_args_and_keyword_only—def f(x, *args, y, **kwargs)workstest_function_with_default_parameter— updated: omitting defaulted param now workstest_default_values_omitted—def f(x, y, z=64)with 2-element configtest_default_values_overridden— explicitly providing a defaulted paramtest_keyword_only_default_omitted—def f(x, *, y=32)with 1-element configtest_too_few_config_args_rejected— negative: fewer args than required paramstest_too_many_config_args_rejected— negative: more args than total paramsDocs
core_concepts.rst: documents supported parameter kinds (regular, keyword-only, defaults,*args/**kwargs)known_issues.rst: notes that*args/**kwargsare tolerated but ignored_sanitize_configsdocstring updated