{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_config/config.py#L257-L293","documentation":"Raised by `set_option` when the positional arguments are not pairs. `set_option` accepts either `(key, value, key, value, ...)` or a single dict; after the dict is flattened, `nargs` must be nonzero and even. An odd or zero count triggers this ValueError before any option lookup happens.","triggerScenarios":"`pd.set_option('display.max_rows')` (value missing), `pd.set_option('a', 1, 'b')` (unbalanced), or `pd.set_option()` with no args.","commonSituations":"Forgetting the value argument; miscounting when setting several options positionally; refactoring that drops one arg.","solutions":["Pass arguments as key/value pairs: `pd.set_option('display.max_rows', 10)`.","For multiple options either pass them as alternating pairs or pass a single dict: `pd.set_option({'display.max_rows': 10, 'display.max_columns': 5})`.","Double-check the count: number of positional args must be even and >= 2."],"exampleFix":"# before\npd.set_option('display.max_rows')        # odd args -> ValueError\n\n# after\npd.set_option('display.max_rows', 10)\n# or\npd.set_option({'display.max_rows': 10, 'display.max_columns': 5})","handlingStrategy":"validation","validationCode":"def safe_set_option(*args):\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    if len(args) % 2 != 0 or len(args) == 0:\n        raise ValueError('set_option needs (key, value) pairs or a single dict')\n    import pandas as pd\n    pd.set_option(*args)\nsafe_set_option('display.max_rows', 10)","typeGuard":"null","tryCatchPattern":"try:\n    pd.set_option(*opts)\nexcept ValueError as e:\n    if 'even number' in str(e):\n        # rebuild opts as pairs/dict and retry\n        ...\n    raise","preventionTips":["Prefer the dict form `set_option({...})` when setting many options — harder to miscount.","Wrap user-facing config code with a pair-count check before calling set_option.","In tests, assert the arg count is even before invoking."],"tags":["config","set-option","argument-count","api-misuse"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}