{"record":{"id":"303a226ba9c7f3b5","repo":"roboflow/supervision","slug":"unsupported-data-type-for-key-key-type-value","errorCode":null,"errorMessage":"Unsupported data type for key '{key}': {type(value)}","messagePattern":"Unsupported data type for key '(.+?)': (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/utils/internal.py","lineNumber":688,"sourceCode":"            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\n    Returns:\n        Array of signed cross-product values, shape (number of anchors,","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/utils/internal.py#L670-L706","documentation":"Raised by get_data_item while indexing/slicing a Detections whose data dictionary holds a value that is neither np.ndarray nor list. When you index Detections (detections[0], detections[mask], detections[1:5]), every data field is subset using array indexing or list comprehension, so only ndarray and list containers are supported.","triggerScenarios":"detections[0], detections[np.array([0,2])], detections[slice], or any __getitem__ path (core.py:225, core.py:2692) on a Detections where a data value is a str, int, float, dict, tuple, etc. Example: data={'source': 'video1.mp4'} then detections[0].","commonSituations":"Storing per-object (not per-detection) metadata inside detections.data instead of detections.metadata; storing a scalar config value in data during prototyping and later filtering the Detections with a boolean mask; converting older code that never indexed Detections, so the bad data value went unnoticed.","solutions":["Move non-per-detection values into Detections.metadata (dict), which is not indexed per detection","Replace the scalar with a list/ndarray of length len(detections), e.g. data={'source': ['video1.mp4'] * len(detections)}","If the value is a container, convert it to np.ndarray before assigning into data"],"exampleFix":"# before\nd = sv.Detections(xyxy=boxes, data={'source': 'cam1'})\nsub = d[0]  # TypeError\n# after\nd = sv.Detections(xyxy=boxes, metadata={'source': 'cam1'})\nsub = d[0]","handlingStrategy":"type-guard","validationCode":"import numpy as np\n\ndef data_is_index_safe(data):\n    return all(isinstance(v, (np.ndarray, list)) for v in data.values())","typeGuard":"def is_index_safe_data(data: dict) -> bool:\n    \"\"\"True when every data value can be subset by get_data_item (ndarray or list).\"\"\"\n    return all(isinstance(v, (np.ndarray, list)) for v in data.values())","tryCatchPattern":"try:\n    sub = detections[idx]\nexcept TypeError as e:\n    if \"Unsupported data type\" in str(e):\n        detections.metadata.update({k: v for k, v in detections.data.items() if not isinstance(v, (np.ndarray, list))})\n        detections.data = {k: v for k, v in detections.data.items() if isinstance(v, (np.ndarray, list))}\n        sub = detections[idx]\n    else:\n        raise","preventionTips":["Keep per-object values in Detections.metadata, never in detections.data","Add an assertion after building Detections that all data values are ndarray/list","Store scalars as length-N arrays: np.full(len(d), value)"],"tags":["detections","data-dict","indexing","typeerror"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}