{"record":{"id":"93326b4d4a5ba963","repo":"pandas-dev/pandas","slug":"must-provide-an-even-number-of-non-keyword-argumen","errorCode":null,"errorMessage":"Must provide an even number of non-keyword arguments","messagePattern":"Must provide an even number of non-keyword arguments","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":275,"sourceCode":"    Dictionary Input:\n\n    >>> pd.set_option({\"display.max_columns\": 4, \"display.precision\": 1})\n    >>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])\n    >>> df\n    0  1  ...  3   4\n    0  1  2  ...  4   5\n    1  6  7  ...  9  10\n    [2 rows x 5 columns]\n    >>> pd.reset_option(\"display.max_columns\")\n    >>> pd.reset_option(\"display.precision\")\n    \"\"\"\n    # Handle dictionary input\n    if len(args) == 1 and isinstance(args[0], dict):\n        args = tuple(kv for item in args[0].items() for kv in item)\n\n    nargs = len(args)\n    if not nargs or nargs % 2 != 0:\n        raise ValueError(\"Must provide an even number of non-keyword arguments\")\n\n    for k, v in zip(args[::2], args[1::2], strict=True):\n        key = _get_single_key(k)\n\n        opt = _get_registered_option(key)\n        if opt and opt.validator:\n            opt.validator(v)\n\n        # walk the nested dict\n        root, k_root = _get_root(key)\n        root[k_root] = v\n\n        if opt is not None and opt.cb:\n            opt.cb(key)\n\n\ndef describe_option(pat: str = \"\", _print_desc: bool = True) -> str | None:\n    \"\"\"","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L257-L293","documentation":"Raised by set_option (config.py:273-275) when called with zero or an odd number of positional arguments, since options must be supplied as (pattern, value) pairs. The single-dict form is handled before this check.","triggerScenarios":"pd.set_option('display.max_columns') (1 arg) or pd.set_option('a', 1, 'b') (3 args), or accidentally passing a dict inside a tuple.","commonSituations":"Missing the value argument, trailing comma in a multi-option call, or refactoring that drops a value.","solutions":["Supply arguments in pairs: pd.set_option('a', 1, 'b', 2).","Pass a single dict: pd.set_option({'display.max_columns': 4, 'display.precision': 1}).","Double-check argument count in dynamically built *args before calling set_option."],"exampleFix":"# before\npd.set_option('display.max_columns', 'display.precision', 2)  # 3 args\n\n# after\npd.set_option('display.max_columns', 10, 'display.precision', 2)","handlingStrategy":"validation","validationCode":"def safe_set_option(*args):\n    assert len(args) >= 2 and len(args) % 2 == 0, 'need (pat, val) pairs'\n    pd.set_option(*args)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the dict form pd.set_option({'a': 1, 'b': 2}) for clarity.","Add a unit test asserting even-length args when building option lists dynamically.","Lint for odd-argument set_option calls in code review."],"tags":["config","set-option","argument-validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}