{"record":{"id":"b84fe541a5b1c8c5","repo":"pandas-dev/pandas","slug":"value-must-be-a-callable","errorCode":null,"errorMessage":"Value must be a callable","messagePattern":"Value must be a callable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":955,"sourceCode":"is_str = is_type_factory(str)\nis_text = is_instance_factory((str, bytes))\n\n\ndef is_callable(obj: object) -> bool:\n    \"\"\"\n\n    Parameters\n    ----------\n    `obj` - the object to be checked\n\n    Returns\n    -------\n    validator - returns True if object is callable\n        raises ValueError otherwise.\n\n    \"\"\"\n    if not callable(obj):\n        raise ValueError(\"Value must be a callable\")\n    return True\n\n\n# import set_module here would cause circular import\nget_option.__module__ = \"pandas\"\nset_option.__module__ = \"pandas\"\ndescribe_option.__module__ = \"pandas\"\nreset_option.__module__ = \"pandas\"\noption_context.__module__ = \"pandas\"\n","sourceCodeStart":937,"sourceCodeEnd":965,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_config/config.py#L937-L965","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before\npd.set_option('display.float_format', '{:.2f}')\n\n// after\npd.set_option('display.float_format', lambda x: f'{x:.2f}')","handlingStrategy":"type-guard","validationCode":"assert callable(value), f'option {name} requires a callable, got {type(value)}'","typeGuard":"from typing import Callable\ndef is_format_callable(v) -> bool:\n    return callable(v)","tryCatchPattern":null,"preventionTips":["Wrap format strings in a lambda before assignment.","Use reset_option rather than assigning None to disable."],"tags":["config","callable-validation","display-options"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}