{"record":{"id":"1e4ea77db9684688","repo":"pandas-dev/pandas","slug":"path-prefix-to-option-option-is-already-an-opt","errorCode":null,"errorMessage":"Path prefix to option '{option}' is already an option","messagePattern":"Path prefix to option '(.+?)' is already an option","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":583,"sourceCode":"    # the default value should be legal\n    if validator:\n        validator(defval)\n\n    # walk the nested dict, creating dicts as needed along the path\n    path = key.split(\".\")\n\n    for k in path:\n        if not re.match(\"^\" + tokenize.Name + \"$\", k):\n            raise ValueError(f\"{k} is not a valid identifier\")\n        if keyword.iskeyword(k):\n            raise ValueError(f\"{k} is a python keyword\")\n\n    cursor = _global_config\n    msg = \"Path prefix to option '{option}' is already an option\"\n\n    for i, p in enumerate(path[:-1]):\n        if not isinstance(cursor, dict):\n            raise OptionError(msg.format(option=\".\".join(path[:i])))\n        if p not in cursor:\n            cursor[p] = {}\n        cursor = cursor[p]\n\n    if not isinstance(cursor, dict):\n        raise OptionError(msg.format(option=\".\".join(path[:-1])))\n\n    # a namespace already lives here, i.e. `key` is a path prefix to one or\n    # more already-registered options; registering it would clobber them\n    # (GH#29242)\n    if isinstance(cursor.get(path[-1]), dict):\n        raise OptionError(f\"Option '{key}' is a prefix of an already-registered option\")\n\n    cursor[path[-1]] = defval  # initialize\n\n    # save the option metadata\n    _registered_options[key] = RegisteredOption(\n        key=key, defval=defval, doc=doc, validator=validator, cb=cb","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L565-L601","documentation":"Raised by register_option (config.py:581-583) when, while walking the dotted key path, a non-final segment resolves to a value that is already a leaf (not a dict). The option being registered would have to traverse an existing leaf to reach a subtree, which is illegal.","triggerScenarios":"cf.register_option('a.b.c', 1) when 'a.b' is already registered as a leaf value (e.g. an int). The walk hits cursor that is not a dict at index i.","commonSituations":"Registering a deeper option under a prefix previously registered as a plain value; mis-ordered registration calls.","solutions":["Register the prefix as a namespace first (only leaf-level options are stored as values; intermediate nodes become dicts automatically only when they are prefixes of newly registered leaves).","Rename the new option to avoid colliding with an existing leaf path.","Inspect _global_config to see which prefix is already a leaf."],"exampleFix":"# before\ncf.register_option('display.x', 1)\ncf.register_option('display.x.y', 2)  # Path prefix to option 'display.x' is already an option\n\n# after\ncf.register_option('display.x_val', 1)\ncf.register_option('display.x.y', 2)","handlingStrategy":"validation","validationCode":"import pandas._config.config as cf\ndef safe_register(key, defval, **kw):\n    cursor = cf._global_config\n    for i, seg in enumerate(key.lower().split('.')[:-1]):\n        if seg not in cursor:\n            break\n        cursor = cursor[seg]\n        if not isinstance(cursor, dict):\n            raise ValueError(f'prefix {\".\".join(key.split(\".\")[:i+1])} is already a leaf')\n    cf.register_option(key, defval, **kw)","typeGuard":null,"tryCatchPattern":"from pandas.errors import OptionError\ntry:\n    cf.register_option(key, defval)\nexcept OptionError:\n    cf.register_option(renamed_key, defval)","preventionTips":["Register parent namespaces before their children, or keep keys flat.","Inspect cf._global_config to detect existing leaf prefixes before registering deeper keys.","Use a single dotted namespace per library to avoid cross-collisions."],"tags":["config","register-option","namespace-conflict"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}