{"record":{"id":"44a373da3219eb3c","repo":"pandas-dev/pandas","slug":"option-key-has-already-been-defined-as-depreca","errorCode":null,"errorMessage":"Option '{key}' has already been defined as deprecated.","messagePattern":"Option '(.+?)' has already been defined as deprecated\\.","errorType":"exception","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":650,"sourceCode":"    rkey : str, optional\n        Name of an option to reroute access to.\n        If specified, any referenced `key` will be\n        re-routed to `rkey` including set/get/reset.\n        rkey must be a fully-qualified option name (e.g \"x.y.z.rkey\").\n        used by the default message if no `msg` is specified.\n    removal_ver : str, optional\n        Specifies the version in which this option will\n        be removed. used by the default message if no `msg` is specified.\n\n    Raises\n    ------\n    OptionError\n        If the specified key has already been deprecated.\n    \"\"\"\n    key = key.lower()\n\n    if key in _deprecated_options:\n        raise OptionError(f\"Option '{key}' has already been defined as deprecated.\")\n\n    _deprecated_options[key] = DeprecatedOption(key, category, msg, rkey, removal_ver)\n\n\n#\n# functions internal to the module\n\n\ndef _select_options(pat: str) -> list[str]:\n    \"\"\"\n    returns a list of keys matching `pat`\n\n    if pat==\"all\", returns all registered options\n    \"\"\"\n    # short-circuit for exact key\n    if pat in _registered_options:\n        return [pat]\n","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L632-L668","documentation":"Raised by deprecate_option (config.py:649-650) when the lowercased key is already present in _deprecated_options. Each option can be deprecated at most once; the deprecation metadata is immutable once set.","triggerScenarios":"cf.deprecate_option('display.foo', FutureWarning) twice, or a library that re-imports and re-deprecates the same key.","commonSituations":"Re-running a deprecation registration (notebook reload, double import), or two libraries deprecating the same key.","solutions":["Guard with `if key not in cf._deprecated_options:` before deprecating.","Idempotently skip if already deprecated by checking the dict first.","Use unique per-library keys so two libraries do not collide on deprecation."],"exampleFix":"# before\ncf.deprecate_option('display.foo', FutureWarning)\ncf.deprecate_option('display.foo', FutureWarning)  # already defined as deprecated\n\n# after\nif 'display.foo' not in cf._deprecated_options:\n    cf.deprecate_option('display.foo', FutureWarning)","handlingStrategy":"validation","validationCode":"import pandas._config.config as cf\ndef safe_deprecate(key, category, **kw):\n    if key.lower() in cf._deprecated_options:\n        return\n    cf.deprecate_option(key, category, **kw)","typeGuard":"def is_deprecated(key: str) -> bool:\n    import pandas._config.config as cf\n    return key.lower() in cf._deprecated_options","tryCatchPattern":"from pandas.errors import OptionError\ntry:\n    cf.deprecate_option(key, category)\nexcept OptionError:\n    pass  # already deprecated","preventionTips":["Make deprecation calls idempotent.","Namespace your library's deprecated keys to avoid collisions with other libraries.","Centralize deprecation declarations in a single init function."],"tags":["config","deprecate-option","duplicate"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}