pandas-dev/pandas · error · ValueError

Value must be a callable

Error message

Value must be a callable

What it means

Raised by `is_callable`, the validator for options whose value must be a python callable (e.g. `display.float_format`, `display.colheader_justify` in some forms, `styler.format` rules, custom indexing backends). The check uses the builtin `callable`; anything returning False triggers the error.

Solutions

  1. Pass a callable that takes one float and returns a string: `lambda x: f'{x:.2f}'`.
  2. To reset, call `pd.reset_option('display.float_format')` instead of assigning None.
  3. Verify with `callable(value)` is True before assigning.

Example fix

// before
pd.set_option('display.float_format', '{:.2f}')

// after
pd.set_option('display.float_format', lambda x: f'{x:.2f}')
Defensive patterns

Strategy: type-guard

Validate before calling

assert callable(value), f'option {name} requires a callable, got {type(value)}'

Type guard

from typing import Callable
def is_format_callable(v) -> bool:
    return callable(v)

Prevention

When it happens

Trigger: `pd.set_option('display.float_format', '{:.2f}'.format)` incorrectly wrapped as a string; passing a method name string instead of the bound method; passing a module or a None where a function is required.

Common situations: Copying a format string from a tutorial and forgetting it must be wrapped in a lambda; passing `None` to 'disable' rather than the documented reset path.

Related errors


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

Appendix: 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 3b7651241d)