roboflow/supervision · error · TypeError
Unsupported index type: {type(index)}
Error message
Unsupported index type: {type(index)} What it means
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.
Source
Thrown at src/supervision/detection/utils/internal.py:686
for key, value in data.items():
if isinstance(value, np.ndarray):
subset_data[key] = value[index]
elif isinstance(value, list):
if isinstance(index, slice):
subset_data[key] = value[index]
elif isinstance(index, list):
subset_data[key] = [value[i] for i in index]
elif isinstance(index, np.ndarray):
if index.dtype == bool:
subset_data[key] = [
value[i] for i, index_value in enumerate(index) if index_value
]
else:
subset_data[key] = [value[i] for i in index]
elif isinstance(index, int):
subset_data[key] = [value[index]]
else:
raise TypeError(f"Unsupported index type: {type(index)}")
else:
raise TypeError(f"Unsupported data type for key '{key}': {type(value)}")
return subset_data
def cross_product(
anchors: npt.NDArray[np.number], vector: Vector
) -> npt.NDArray[np.number]:
"""Get signed z-component of cross product (2-D determinant) per anchor.
Replaces the deprecated `np.cross` 2-D path (NumPy 2.0) with an explicit
determinant: ``a[..., 0] * b[..., 1] - a[..., 1] * b[..., 0]``.
Args:
anchors: Array of anchors of shape (number of anchors, detections, 2).
vector: Vector to calculate cross product with.
View on GitHub (pinned to 7f254d9784)
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
Example fix
# before sub = detections[np.nonzero(mask)[0] * 1.0] # float index # after sub = detections[np.nonzero(mask)[0].astype(int)]
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np
def coerce_index(idx):
if isinstance(idx, np.ndarray):
if idx.dtype == bool:
return idx
return idx.astype(int)
if isinstance(idx, (int, np.integer)):
return int(idx)
if isinstance(idx, (list, slice)):
return idx
raise TypeError(f"bad index type: {type(idx)}") Type guard
def is_valid_detections_index(idx) -> bool:
import numpy as np
if isinstance(idx, (int, slice)) or isinstance(idx, list):
return True
return isinstance(idx, np.ndarray) and idx.dtype.kind in ('i', 'u', 'b') Try / catch
try:
sub = detections[idx]
except TypeError as e:
if "Unsupported index type" in str(e):
sub = detections[np.asarray(idx).astype(int)]
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported data type for key '{key}': {type(value)}
- Inconsistent data types for key '{key}'. Only np.ndarray and
- Conflicting metadata for key: '{key}': {type(value)}, {type(
- Unexpected array dimension for key '{key}'.
- Object of type {type(value).__name__} is not JSON serializab
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/0d6b22b9b3d8b268.
Report an issue: GitHub.