{"record":{"id":"0d6b22b9b3d8b268","repo":"roboflow/supervision","slug":"unsupported-index-type-type-index","errorCode":null,"errorMessage":"Unsupported index type: {type(index)}","messagePattern":"Unsupported index type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/utils/internal.py","lineNumber":686,"sourceCode":"    for key, value in data.items():\n        if isinstance(value, np.ndarray):\n            subset_data[key] = value[index]\n        elif isinstance(value, list):\n            if isinstance(index, slice):\n                subset_data[key] = value[index]\n            elif isinstance(index, list):\n                subset_data[key] = [value[i] for i in index]\n            elif isinstance(index, np.ndarray):\n                if index.dtype == bool:\n                    subset_data[key] = [\n                        value[i] for i, index_value in enumerate(index) if index_value\n                    ]\n                else:\n                    subset_data[key] = [value[i] for i in index]\n            elif isinstance(index, int):\n                subset_data[key] = [value[index]]\n            else:\n                raise TypeError(f\"Unsupported index type: {type(index)}\")\n        else:\n            raise TypeError(f\"Unsupported data type for key '{key}': {type(value)}\")\n\n    return subset_data\n\n\ndef cross_product(\n    anchors: npt.NDArray[np.number], vector: Vector\n) -> npt.NDArray[np.number]:\n    \"\"\"Get signed z-component of cross product (2-D determinant) per anchor.\n\n    Replaces the deprecated `np.cross` 2-D path (NumPy 2.0) with an explicit\n    determinant: ``a[..., 0] * b[..., 1] - a[..., 1] * b[..., 0]``.\n\n    Args:\n        anchors: Array of anchors of shape (number of anchors, detections, 2).\n        vector: Vector to calculate cross product with.\n","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/utils/internal.py#L668-L704","documentation":"Raised by get_data_item when a Detections is indexed with an index whose type is not slice, list of ints, int, or integer/boolean np.ndarray, and the Detections has at least one list-typed data field. ndarray data values would instead raise a NumPy indexing error, so this guard fires only on the list-comprehension path.","triggerScenarios":"detections[0.0], detections[(0, 1)], detections[np.array([0.5])] or any exotic index type applied to a Detections whose data contains a list value. Float indices from np.argwhere-derived code (forgetting .astype(int) or .tolist() of ints) are typical.","commonSituations":"Passing a float or float array produced by filtering code (e.g. np.where result passed through arithmetic) directly as an index; using a tuple index copied from ndarray idioms; wrapping an index in a dtype=object array.","solutions":["Convert the index to int first: idx = np.asarray(idx).astype(int) or int(idx)","Use canonical index forms: a Python int, list[int], slice, or np.ndarray of integer/bool dtype","Check type of computed indices with isinstance before indexing Detections"],"exampleFix":"# before\nsub = detections[np.nonzero(mask)[0] * 1.0]  # float index\n# after\nsub = detections[np.nonzero(mask)[0].astype(int)]","handlingStrategy":"type-guard","validationCode":"import numpy as np\n\ndef coerce_index(idx):\n    if isinstance(idx, np.ndarray):\n        if idx.dtype == bool:\n            return idx\n        return idx.astype(int)\n    if isinstance(idx, (int, np.integer)):\n        return int(idx)\n    if isinstance(idx, (list, slice)):\n        return idx\n    raise TypeError(f\"bad index type: {type(idx)}\")","typeGuard":"def is_valid_detections_index(idx) -> bool:\n    import numpy as np\n    if isinstance(idx, (int, slice)) or isinstance(idx, list):\n        return True\n    return isinstance(idx, np.ndarray) and idx.dtype.kind in ('i', 'u', 'b')","tryCatchPattern":"try:\n    sub = detections[idx]\nexcept TypeError as e:\n    if \"Unsupported index type\" in str(e):\n        sub = detections[np.asarray(idx).astype(int)]\n    else:\n        raise","preventionTips":["Convert indices to int explicitly after np.where/argwhere arithmetic","Never index Detections with floats or tuples","Centralize index computation in one helper that always returns int arrays"],"tags":["detections","indexing","typeerror","numpy"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}