pandas-dev/pandas · error · OptionError
No such option
Error message
No such option
What it means
Raised by DictWrapper.__getattr__ (config.py:437-438) when the requested attribute key is not present in the underlying nested dict. Chained from the internal KeyError. OptionError subclasses AttributeError, so hasattr/getattr semantics work as expected.
Source
Thrown at pandas/_config/config.py:438
if prefix:
prefix += "."
prefix += key
# you can't set new keys
# can you can't overwrite subtrees
if key in self.d and not isinstance(self.d[key], dict):
set_option(prefix, val)
else:
raise OptionError("You can only set the value of existing options")
def __getattr__(self, key: str) -> Any:
prefix = object.__getattribute__(self, "prefix")
if prefix:
prefix += "."
prefix += key
try:
v = object.__getattribute__(self, "d")[key]
except KeyError as err:
raise OptionError("No such option") from err
if isinstance(v, dict):
return DictWrapper(v, prefix)
else:
return get_option(prefix)
def __dir__(self) -> list[str]:
return list(self.d.keys())
options = DictWrapper(_global_config)
# DictWrapper defines a custom setattr
object.__setattr__(options, "__module__", "pandas")
#
# Functions for use by pandas developers, in addition to User - api
@contextmanagerView on GitHub (pinned to 71959b8cb9)
Solutions
- List valid attributes via dir(pd.options.display) or pd.describe_option('display').
- Use the function API pd.get_option('display.x') with try/except OptionError.
- Catch AttributeError (OptionError is a subclass) for optional-option handling.
Example fix
# before pd.options.display.context # OptionError: No such option # after pd.options.display.max_columns # an existing leaf
Defensive patterns
Strategy: type-guard
Validate before calling
def get_attr_option(root, key, default=None):
d = object.__getattribute__(root, 'd')
if key not in d:
return default
return getattr(root, key) Type guard
def has_option_attr(root, key: str) -> bool:
d = object.__getattribute__(root, 'd')
return key in d Try / catch
from pandas.errors import OptionError
try:
val = getattr(pd.options.display, key)
except OptionError:
val = None Prevention
- Use dir(pd.options.<namespace>) to enumerate valid attributes.
- Treat OptionError as AttributeError (it is one) for hasattr-style checks.
- Prefer the function API pd.get_option for user-facing option names.
When it happens
Trigger: pd.options.context (no such attribute) or pd.options.display.nonexistent.
Common situations: Accessing a typo'd or removed option via attribute syntax; using getattr-style introspection on a namespace that does not contain the leaf.
Related errors
- You can only set the value of existing options
- No such keys(s): {pat!r}
- Pattern matched multiple keys
- Must provide an even number of non-keyword arguments
- No such keys(s) for {pat=}
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/4c99fbba121e89f5.
Report an issue: GitHub.