{"record":{"id":"083e2ec8798a4c3a","repo":"pandas-dev/pandas","slug":"value-must-be-a-nonnegative-integer-or-none","errorCode":null,"errorMessage":"Value must be a nonnegative integer or None","messagePattern":"Value must be a nonnegative integer or None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/_config/config.py","lineNumber":929,"sourceCode":"    Parameters\n    ----------\n    value : None or int\n            The `value` to be checked.\n\n    Raises\n    ------\n    ValueError\n        When the value is not None or is a negative integer\n    \"\"\"\n    if value is None:\n        return\n\n    elif isinstance(value, int):\n        if value >= 0:\n            return\n\n    msg = \"Value must be a nonnegative integer or None\"\n    raise ValueError(msg)\n\n\n# common type validators, for convenience\n# usage: register_option(... , validator = is_int)\nis_int = is_type_factory(int)\nis_bool = is_type_factory(bool)\nis_float = is_type_factory(float)\nis_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","sourceCodeStart":911,"sourceCodeEnd":947,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_config/config.py#L911-L947","documentation":"Raised by the is_nonnegative_int validator (config.py:907-929), which accepts only None or an int >= 0. Any other type (str, float, negative int, bool-passed-as-int) raises ValueError. This validator is a public helper (cf.is_nonnegative_int) used by custom register_option calls and is exercised in tests (test_config.py:229).","triggerScenarios":"Registering an option with validator=cf.is_nonnegative_int and then calling set_option with a negative int, a float like 1.5, a string '5', or any non-int non-None object. The default value passed at registration time is also validated, so a bad default (e.g. -2) triggers it immediately.","commonSituations":"Pulling a numeric setting from an env var or config file as a string and passing it straight to set_option; using a float where an integer count (rows, precision, display width) is required; attempting -1 as a sentinel.","solutions":["Convert the value to int first: pd.set_option('your.key', int(value)).","Use None instead of a negative number to mean 'unlimited'.","If reading from config, validate/coerce with int() in a try/except before calling set_option."],"exampleFix":"# before\npd.set_option('display.max_rows', '-1')\n\n# after\npd.set_option('display.max_rows', None)  # or a concrete int >= 0","handlingStrategy":"validation","validationCode":"value = get_raw()\nif value is None or (isinstance(value, int) and not isinstance(value, bool) and value >= 0):\n    pd.set_option('your.key', value)\nelse:\n    raise ValueError('must be a nonnegative int or None')","typeGuard":"def is_nonneg_int_or_none(value: object) -> bool:\n    return value is None or (isinstance(value, int) and not isinstance(value, bool) and value >= 0)","tryCatchPattern":null,"preventionTips":["Coerce env-var/config strings with int() before setting.","Guard against bool sneaking in (bool is a subclass of int) with an explicit check.","Use None to mean 'unlimited' rather than -1."],"tags":["config","validation","set-option","integer","valueerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}