{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_config/config.py#L632-L668","documentation":"Raised by `deprecate_option` when the (lowercased) key is already present in `_deprecated_options`. An option can only be deprecated once; calling `deprecate_option` twice for the same key — or deprecating a key pandas already deprecated internally — triggers this OptionError.","triggerScenarios":"`deprecate_option('x', DeprecationWarning)` called twice; or deprecating an option that pandas itself already marked deprecated in the current version.","commonSituations":"Library code deprecating an option that pandas deprecated in a newer release; re-running deprecation registration on module reload; double deprecation in tests.","solutions":["Check `_deprecated_options` first: `from pandas._config.config import _deprecated_options; key in _deprecated_options`.","Deprecate each key exactly once; guard registration behind an idempotency check.","If pandas already deprecated the key, rely on its deprecation rather than adding your own."],"exampleFix":"# before\nfrom pandas._config.config import deprecate_option\ndeprecate_option('x', DeprecationWarning)\ndeprecate_option('x', DeprecationWarning)   # OptionError: already deprecated\n\n# after\nfrom pandas._config.config import deprecate_option, _deprecated_options\nif 'x' not in _deprecated_options:\n    deprecate_option('x', DeprecationWarning)","handlingStrategy":"validation","validationCode":"from pandas._config.config import _deprecated_options\ndef safe_deprecate(key: str, category):\n    if key.lower() in _deprecated_options:\n        return  # already deprecated\n    from pandas._config.config import deprecate_option\n    deprecate_option(key, category)","typeGuard":"def is_deprecated(key: str) -> bool:\n    import pandas._config.config as c\n    return key.lower() in c._deprecated_options","tryCatchPattern":"from pandas._config.config import OptionError\ntry:\n    deprecate_option(key, category)\nexcept OptionError:\n    # already deprecated; nothing to do\n    ...","preventionTips":["Guard deprecation calls with a `_deprecated_options` membership check.","Make module-level deprecations idempotent for safe reload.","Avoid deprecating keys pandas already deprecated in your supported versions."],"tags":["config","deprecate-option","duplicate","option-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}