roboflow/supervision · error · TypeError

Unsupported data type for key '{key}': {type(value)}

Error message

Unsupported data type for key '{key}': {type(value)}

What it means

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.

Source

Thrown at src/supervision/detection/utils/internal.py:688

            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.

    Returns:
        Array of signed cross-product values, shape (number of anchors,

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Move non-per-detection values into Detections.metadata (dict), which is not indexed per detection
  2. Replace the scalar with a list/ndarray of length len(detections), e.g. data={'source': ['video1.mp4'] * len(detections)}
  3. If the value is a container, convert it to np.ndarray before assigning into data

Example fix

# before
d = sv.Detections(xyxy=boxes, data={'source': 'cam1'})
sub = d[0]  # TypeError
# after
d = sv.Detections(xyxy=boxes, metadata={'source': 'cam1'})
sub = d[0]
Defensive patterns

Strategy: type-guard

Validate before calling

import numpy as np

def data_is_index_safe(data):
    return all(isinstance(v, (np.ndarray, list)) for v in data.values())

Type guard

def is_index_safe_data(data: dict) -> bool:
    """True when every data value can be subset by get_data_item (ndarray or list)."""
    return all(isinstance(v, (np.ndarray, list)) for v in data.values())

Try / catch

try:
    sub = detections[idx]
except TypeError as e:
    if "Unsupported data type" in str(e):
        detections.metadata.update({k: v for k, v in detections.data.items() if not isinstance(v, (np.ndarray, list))})
        detections.data = {k: v for k, v in detections.data.items() if isinstance(v, (np.ndarray, list))}
        sub = detections[idx]
    else:
        raise

Prevention

When it happens

Trigger: 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].

Common situations: 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.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/303a226ba9c7f3b5. Report an issue: GitHub.