{"record":{"id":"2e3c105df5c641a5","repo":"pandas-dev/pandas","slug":"must-be-block-or-integer-type","errorCode":null,"errorMessage":"must be block or integer type","messagePattern":"must be block or integer type","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/sparse/array.py","lineNumber":2166,"sourceCode":"\n\n@overload\ndef make_sparse_index(length: int, indices, kind: Literal[\"block\"]) -> BlockIndex: ...\n\n\n@overload\ndef make_sparse_index(length: int, indices, kind: Literal[\"integer\"]) -> IntIndex: ...\n\n\ndef make_sparse_index(length: int, indices, kind: SparseIndexKind) -> SparseIndex:\n    index: SparseIndex\n    if kind == \"block\":\n        locs, lens = splib.get_blocks(indices)\n        index = BlockIndex(length, locs, lens)\n    elif kind == \"integer\":\n        index = IntIndex(length, indices)\n    else:  # pragma: no cover\n        raise ValueError(\"must be block or integer type\")\n    return index\n","sourceCodeStart":2148,"sourceCodeEnd":2168,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/sparse/array.py#L2148-L2168","documentation":"Raised by make_sparse_index when the `kind` argument is neither 'block' nor 'integer'. These are the only two SparseIndex implementations (BlockIndex and IntIndex); any other string corrupts the dispatch and is rejected. The 'pragma: no cover' on the else indicates it is treated as an internal-invariant guard rather than a user-facing path.","triggerScenarios":"Constructing a SparseArray with kind='dense', kind=None, or a typo like kind='int'. User-facing exposure is via SparseArray(..., kind=...) and SparseDtype(..., kind=...).","commonSituations":"Typing the kind argument, passing a variable that was supposed to be 'integer'/'block' but is None, or copying code from an older pandas version that accepted different spellings.","solutions":["Use exactly 'block' or 'integer' for kind.","Omit kind to accept the default ('integer' is common) when unsure.","Validate at the call site: assert kind in {'block','integer'}."],"exampleFix":"// before\nsa = pd.arrays.SparseArray([0,1,0], kind='int')  # raises 'must be block or integer'\n\n// after\nsa = pd.arrays.SparseArray([0,1,0], kind='integer')","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef make_sparse_safe(values, kind='integer', fill_value=None):\n    if kind not in {'block', 'integer'}:\n        raise ValueError(\"kind must be 'block' or 'integer'\")\n    return pd.arrays.SparseArray(values, kind=kind, fill_value=fill_value)","typeGuard":"def is_valid_sparse_kind(kind) -> bool:\n    return kind in {'block', 'integer'}","tryCatchPattern":"try:\n    sa = pd.arrays.SparseArray(values, kind=kind)\nexcept ValueError as e:\n    if 'block or integer' in str(e):\n        sa = pd.arrays.SparseArray(values, kind='integer')\n    else:\n        raise","preventionTips":["Restrict kind to {'block','integer'}; omit the argument to use the default","Validate kind at the call site rather than relying on internal dispatch","Avoid passing kind=None"],"tags":["sparse","constructor","kind","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}