{"record":{"id":"9093eb8c4f37d6a4","repo":"pandas-dev/pandas","slug":"pattern-matched-multiple-keys","errorCode":null,"errorMessage":"Pattern matched multiple keys","messagePattern":"Pattern matched multiple keys","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":134,"sourceCode":"    >>> pd.options.context\n    Traceback (most recent call last):\n    OptionError: No such option\n    \"\"\"\n\n    __module__ = \"pandas.errors\"\n\n\n#\n# User API\n\n\ndef _get_single_key(pat: str) -> str:\n    keys = _select_options(pat)\n    if len(keys) == 0:\n        _warn_if_deprecated(pat)\n        raise OptionError(f\"No such keys(s): {pat!r}\")\n    if len(keys) > 1:\n        raise OptionError(\"Pattern matched multiple keys\")\n    key = keys[0]\n\n    _warn_if_deprecated(key)\n\n    key = _translate_key(key)\n\n    return key\n\n\ndef get_option(pat: str) -> Any:\n    \"\"\"\n    Retrieve the value of the specified option.\n\n    This method allows users to query the current value of a given option\n    in the pandas configuration system. Options control various display,\n    performance, and behavior-related settings within pandas.\n\n    Parameters","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_config/config.py#L116-L152","documentation":"Raised by `_get_single_key` when `_select_options(pat)` returns more than one key, meaning the pattern is ambiguous. Because `pat` is matched with `re.search(..., re.I)` over all registered keys, short substrings like `display` or `max` hit many options and pandas refuses to guess.","triggerScenarios":"`pd.get_option('display')`, `pd.get_option('max')`, or any substring/regex that matches two or more registered option keys.","commonSituations":"Using a partial option name for brevity; relying on a substring that later became ambiguous when pandas added a new option with a similar name (the documented stability warning in `get_option`).","solutions":["Use the full, exact option key (e.g. `display.max_columns`).","Add enough characters to make the pattern uniquely match a single key.","Call `pd.describe_option('yourpattern')` to see exactly which keys match before using get/set."],"exampleFix":"# before\npd.get_option('max')   # matches max_rows, max_columns, ... -> OptionError\n\n# after\npd.get_option('display.max_columns')","handlingStrategy":"validation","validationCode":"from pandas._config.config import _select_options\ndef is_unique_option(pat: str) -> bool:\n    matches = _select_options(pat)\n    return len(matches) == 1, matches\nunique, matches = is_unique_option('display')\nif not unique:\n    # lengthen pat or pick from matches","typeGuard":"def unique_option_match(pat: str) -> str | None:\n    import pandas._config.config as c\n    keys = c._select_options(pat)\n    return keys[0] if len(keys) == 1 else None","tryCatchPattern":"from pandas._config.config import OptionError\ntry:\n    pd.get_option(pat)\nexcept OptionError as e:\n    if 'Pattern matched multiple keys' in str(e):\n        matches = pd._config.config._select_options(pat)\n        # disambiguate by picking the intended full key\n    ...","preventionTips":["Never rely on short substrings for production code; use full keys.","Use `pd.describe_option(pat)` to preview matches before get/set.","Add a regression note if a new option you register could make an existing partial match ambiguous."],"tags":["config","option","ambiguous","regex","option-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}