{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L116-L152","documentation":"Raised by _get_single_key (config.py:133-134) when the supplied pattern matches more than one registered option key. The API requires an unambiguous match because get/set operate on a single value; multiple matches are rejected rather than guessing.","triggerScenarios":"pd.get_option('display') matches display.max_rows, display.max_columns, etc. Likewise pd.set_option('display', 5) or pd.reset_option('display.max') (here reset raises the 4-char rule instead).","commonSituations":"Using an over-broad prefix to be 'convenient', then a future pandas release adds another option sharing that prefix, making a previously-unique match ambiguous.","solutions":["Use the fully-qualified option name, e.g. 'display.max_columns' instead of 'display'.","Use pd.describe_option(pat) to see which keys the pattern resolves to, then narrow the pattern.","Pin the full key in a constant rather than relying on partial matching."],"exampleFix":"# before\npd.get_option('display')  # Pattern matched multiple keys\n\n# after\npd.get_option('display.max_columns')","handlingStrategy":"validation","validationCode":"import pandas._config.config as cf\ndef is_unambiguous(pat: str) -> bool:\n    return len(cf._select_options(pat)) == 1\nassert is_unambiguous(pat), f'{pat!r} is ambiguous or unknown'","typeGuard":"def is_single_match(pat: str) -> bool:\n    import pandas._config.config as cf\n    return len(cf._select_options(pat)) == 1","tryCatchPattern":"from pandas.errors import OptionError\ntry:\n    pd.get_option(pat)\nexcept OptionError as e:\n    if 'multiple keys' in str(e):\n        matches = cf._select_options(pat)\n        pat = matches[0] if len(matches) == 1 else None","preventionTips":["Use full dotted names like 'display.max_columns', never bare prefixes in production.","Pin option names to constants so refactors stay consistent.","When a new pandas release ships, re-test code that relied on partial matches."],"tags":["config","options","ambiguous-match"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}