{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_config/config.py#L911-L947","documentation":"Raised by `is_nonnegative_int`, the validator used for options that accept `None` or a nonnegative python int (e.g. `display.max_rows`, `display.max_columns`, `display.width` when None means unlimited). It explicitly rejects negative ints, booleans (which are technically ints but semantically wrong), floats, and strings. `None` short-circuits as 'unlimited'.","triggerScenarios":"`pd.set_option('display.max_rows', -1)`; `pd.set_option('display.max_columns', 5.0)` (float); `pd.set_option('display.max_rows', '50')` (string); passing a numpy integer where a plain int is required may also fail the `isinstance(value, int)` branch for some configurations.","commonSituations":"Off-by-one thinking where -1 means 'all' (it does not — None does); JSON config decoded into floats; using np.int64 from array operations as the value.","solutions":["Use None to mean 'unlimited' rather than -1.","Coerce the value with `int(x)` after confirming `x >= 0`.","Avoid passing numpy scalars; convert with `int(np_value)` first."],"exampleFix":"// before\npd.set_option('display.max_rows', -1)\n\n// after\npd.set_option('display.max_rows', None)","handlingStrategy":"validation","validationCode":"def coerce_nonneg_int(v):\n    if v is None:\n        return None\n    iv = int(v)\n    if iv < 0:\n        raise ValueError('must be >=0 or None')\n    return iv","typeGuard":"def is_nonneg_int_or_none(v) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 0)","tryCatchPattern":null,"preventionTips":["Use None, not -1, for 'unlimited'.","Always int() values loaded from JSON before passing to set_option."],"tags":["config","integer-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"}