pandas-dev/pandas · error · ValueError
Must provide an even number of non-keyword arguments
Error message
Must provide an even number of non-keyword arguments
What it means
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.
Source
Thrown at pandas/_config/config.py:275
Dictionary Input:
>>> pd.set_option({"display.max_columns": 4, "display.precision": 1})
>>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
>>> df
0 1 ... 3 4
0 1 2 ... 4 5
1 6 7 ... 9 10
[2 rows x 5 columns]
>>> pd.reset_option("display.max_columns")
>>> pd.reset_option("display.precision")
"""
# Handle dictionary input
if len(args) == 1 and isinstance(args[0], dict):
args = tuple(kv for item in args[0].items() for kv in item)
nargs = len(args)
if not nargs or nargs % 2 != 0:
raise ValueError("Must provide an even number of non-keyword arguments")
for k, v in zip(args[::2], args[1::2], strict=True):
key = _get_single_key(k)
opt = _get_registered_option(key)
if opt and opt.validator:
opt.validator(v)
# walk the nested dict
root, k_root = _get_root(key)
root[k_root] = v
if opt is not None and opt.cb:
opt.cb(key)
def describe_option(pat: str = "", _print_desc: bool = True) -> str | None:
"""View on GitHub (pinned to 71959b8cb9)
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.
Example fix
# before
pd.set_option('display.max_columns', 'display.precision', 2) # 3 args
# after
pd.set_option('display.max_columns', 10, 'display.precision', 2) Defensive patterns
Strategy: validation
Validate before calling
def safe_set_option(*args):
assert len(args) >= 2 and len(args) % 2 == 0, 'need (pat, val) pairs'
pd.set_option(*args) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Missing the value argument, trailing comma in a multi-option call, or refactoring that drops a value.
Related errors
- Provide an even amount of arguments as option_context(pat, v
- Value must be an instance of {type_repr}
- Value must be one of {pp_values}
- Value must be a nonnegative integer or None
- Value must be a callable
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/93326b4d4a5ba963.
Report an issue: GitHub.