pandas-dev/pandas · error · OptionError

No such option

Error message

No such option

What it means

Raised by `DictWrapper.__getattr__` (the `pd.options.<...>` read API) when the requested attribute is not a key in the current config dict. `OptionError` subclasses both `AttributeError` and `KeyError`, so `hasattr`/`getattr(..., default)` and `except KeyError` both behave correctly.

Solutions

  1. Use `dir(pd.options)` or `pd.describe_option()` to see valid names and read with the exact key.
  2. Prefer the function API `pd.get_option(key)` if you are unsure the key exists.
  3. Guard attribute access with `getattr(pd.options, name, default)`.

Example fix

# before
pd.options.contex   # typo -> OptionError: No such option

# after
pd.options.context   # if that is the intended attribute
# or safely:
getattr(pd.options, 'contex', None)
Defensive patterns

Strategy: type-guard

Validate before calling

import pandas as pd
def safe_option_attr(path: str, default=None):
    node = pd.options
    for p in path.split('.'):
        if not hasattr(node, p):
            return default
        node = getattr(node, p)
    return node

Type guard

def option_attr_exists(path: str) -> bool:
    import pandas as pd
    node = pd.options
    for p in path.split('.'):
        if not hasattr(node, p):
            return False
        node = getattr(node, p)
    return True

Try / catch

from pandas._config.config import OptionError
try:
    val = getattr(pd.options, name)
except OptionError:
    # also catch AttributeError/KeyError (OptionError subclasses both)
    val = default

Prevention

When it happens

Trigger: `pd.options.context`, `pd.options.nonexistent`, or reading any attribute that is not part of the option tree.

Common situations: Typo reading an option via attribute access; expecting a method/property on `pd.options` that does not exist; copy-paste from another library's option API.

Related errors


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

Appendix: 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


@contextmanager

View on GitHub (pinned to 3b7651241d)