pandas-dev/pandas · error · ValueError

Value must be a callable

Error message

Value must be a callable

What it means

Raised by the is_callable validator (config.py:941-955), a public helper for register_option. It calls the builtin callable() check; if the option value is not callable it raises ValueError('Value must be a callable'). Used for options whose value must be a function/lambda.

Source

Thrown at pandas/_config/config.py:955

is_str = is_type_factory(str)
is_text = is_instance_factory((str, bytes))


def is_callable(obj: object) -> bool:
    """

    Parameters
    ----------
    `obj` - the object to be checked

    Returns
    -------
    validator - returns True if object is callable
        raises ValueError otherwise.

    """
    if not callable(obj):
        raise ValueError("Value must be a callable")
    return True


# import set_module here would cause circular import
get_option.__module__ = "pandas"
set_option.__module__ = "pandas"
describe_option.__module__ = "pandas"
reset_option.__module__ = "pandas"
option_context.__module__ = "pandas"

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Pass the actual callable object (function, lambda, or bound method), not its name.
  2. If the option should accept non-callables, pick a different validator (is_text, is_one_of_factory) or no validator.
  3. Verify with callable(value) before calling set_option.

Example fix

# before
pd.set_option('my.callback', 'format_func')

# after
def format_func(x):
    return str(x)
pd.set_option('my.callback', format_func)
Defensive patterns

Strategy: type-guard

Validate before calling

obj = get_callback()
if not callable(obj):
    raise TypeError('option value must be callable')
pd.set_option('my.callback', obj)

Type guard

from typing import Callable

def is_callable_value(value: object) -> bool:
    return callable(value)

Prevention

When it happens

Trigger: Registering an option with validator=cf.is_callable and then setting it to a non-callable value (a string, an int, an object). Also fires at registration if the default value passed is not callable.

Common situations: Setting a callback-style option to a string name instead of the function object; passing a method name rather than a bound method; registering a formatter option and supplying a template string.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/b84fe541a5b1c8c5. Report an issue: GitHub.