pandas-dev/pandas · error · OptionError
No such keys(s): {pat!r}
Error message
No such keys(s): {pat!r} What it means
Raised by _get_single_key (pandas/_config/config.py:128-132) when no registered option key matches the pattern. Affects get_option/set_option/get_default_val. OptionError subclasses both AttributeError and KeyError, so existing KeyError handlers remain compatible.
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 71959b8cb9)
Solutions
- List valid options with `pd.describe_option()` (no args) and copy the exact fully-qualified name.
- Validate the pattern before use: `import pandas._config.config as cf; [k for k in cf._registered_options if 'display' in k]`.
- Catch OptionError (it subclasses KeyError/AttributeError) and fall back to a default.
Example fix
# before
pd.get_option('display.max_col') # No such keys(s): 'display.max_col'
# after
pd.get_option('display.max_columns') Defensive patterns
Strategy: validation
Validate before calling
import pandas._config.config as cf
def option_exists(pat: str) -> bool:
return len(cf._select_options(pat)) == 1
assert option_exists('display.max_columns'), 'use pd.describe_option() to list valid keys' Type guard
def is_known_option(pat: str) -> bool:
import pandas._config.config as cf
return len(cf._select_options(pat)) == 1 Try / catch
from pandas.errors import OptionError
try:
val = pd.get_option(pat)
except OptionError:
val = default_val Prevention
- Store frequently used option names in module-level constants.
- Call pd.describe_option() once to enumerate valid keys.
- Avoid partial pattern matching in production code; use fully-qualified names.
When it happens
Trigger: Calling pd.get_option('display.foo') or pd.set_option('nonexistent.option', 1) where the pattern matches zero entries in _registered_options.
Common situations: Typo in an option name, using an option that was renamed/removed in a newer pandas version, or copy-pasting an option name from outdated documentation.
Related errors
- Value must be a positive integer or None
- Value must be one of python|pyarrow
- Pattern matched multiple keys
- No such keys(s) for {pat=}
- {k} is not a valid identifier
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/748a38d45b16941d.
Report an issue: GitHub.