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
- Pass a callable that takes one float and returns a string: `lambda x: f'{x:.2f}'`.
- To reset, call `pd.reset_option('display.float_format')` instead of assigning None.
- 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
- Wrap format strings in a lambda before assignment.
- Use reset_option rather than assigning None to disable.
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
- Value must be a nonnegative integer or None
- is a python keyword
- is not a valid identifier
- Must provide an even number of non-keyword arguments
- No such keys(s) for
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)