{"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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L937-L965","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the actual callable object (function, lambda, or bound method), not its name.","If the option should accept non-callables, pick a different validator (is_text, is_one_of_factory) or no validator.","Verify with callable(value) before calling set_option."],"exampleFix":"# before\npd.set_option('my.callback', 'format_func')\n\n# after\ndef format_func(x):\n    return str(x)\npd.set_option('my.callback', format_func)","handlingStrategy":"type-guard","validationCode":"obj = get_callback()\nif not callable(obj):\n    raise TypeError('option value must be callable')\npd.set_option('my.callback', obj)","typeGuard":"from typing import Callable\n\ndef is_callable_value(value: object) -> bool:\n    return callable(value)","tryCatchPattern":null,"preventionTips":["Pass the function object, never its name as a string.","Assert callable(value) in a test that sets callback options.","When registering an option, pick a validator matching the intended value type."],"tags":["config","validation","callable","set-option","valueerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}