pandas-dev/pandas · error · OptionError

No such keys(s)

Error message

No such keys(s): {pat!r}

What it means

Raised by `_get_single_key` (used by `get_option` and `set_option`) when `_select_options(pat)` returns zero matches. `pat` is treated case-insensitively and as a regex via `re.search`, with an exact-match short-circuit. If nothing in `_registered_options` matches, this OptionError (subclass of AttributeError and KeyError) is thrown after checking for deprecation warnings.

Solutions

  1. List/inspect available options with `pd.describe_option()` (no arg lists all) to find the correct name.
  2. Use the fully-qualified key, e.g. `pd.get_option('display.max_columns')`, not an abbreviation.
  3. Check the pandas version and the changelog if the option existed before — it may have been renamed/removed.
  4. Escape regex metacharacters if your pattern intentionally contains `.`, `*`, etc.

Example fix

# before
pd.get_option('display.max_colmns')   # typo -> OptionError

# after
pd.describe_option()                  # find the real name
pd.get_option('display.max_columns')
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd
from pandas._config.config import _select_options
def option_exists(pat: str) -> bool:
    return len(_select_options(pat)) == 1
if option_exists('display.max_columns'):
    val = pd.get_option('display.max_columns')

Type guard

def is_known_option(pat: str) -> bool:
    import pandas._config.config as c
    return len(c._select_options(pat)) == 1

Try / catch

from pandas.errors import AbstractMethodError  # placeholder; OptionError lives in pandas._config.config
from pandas._config.config import OptionError
try:
    pd.get_option(maybe_bad_key)
except OptionError as e:
    # handle unknown option (also caught by KeyError/AttributeError base classes)
    ...

Prevention

When it happens

Trigger: `pd.get_option('display.max_colmns')` (typo), `pd.set_option('foo.bar', 1)` where `foo.bar` was never registered, or any pattern that matches no registered option key.

Common situations: Typo in an option name; using an option that was removed/renamed in a newer pandas version; copy-pasting an option name from an outdated tutorial; case confusion is rare (keys are lowercased) but regex special chars in the pattern matching nothing.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/748a38d45b16941d. Report an issue: GitHub.

Appendix: source

Thrown at pandas/_config/config.py:132

    Examples
    --------
    >>> pd.options.context
    Traceback (most recent call last):
    OptionError: No such option
    """

    __module__ = "pandas.errors"


#
# User API


def _get_single_key(pat: str) -> str:
    keys = _select_options(pat)
    if len(keys) == 0:
        _warn_if_deprecated(pat)
        raise OptionError(f"No such keys(s): {pat!r}")
    if len(keys) > 1:
        raise OptionError("Pattern matched multiple keys")
    key = keys[0]

    _warn_if_deprecated(key)

    key = _translate_key(key)

    return key


def get_option(pat: str) -> Any:
    """
    Retrieve the value of the specified option.

    This method allows users to query the current value of a given option
    in the pandas configuration system. Options control various display,
    performance, and behavior-related settings within pandas.

View on GitHub (pinned to 3b7651241d)