{"record":{"id":"0e77c2da00ee3afb","repo":"roboflow/supervision","slug":"custom-values-must-be-either-a-numpy-array-or-a-li","errorCode":null,"errorMessage":"custom_values must be either a numpy array or a list of floats.","messagePattern":"custom_values must be either a numpy array or a list of floats\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/supervision/annotators/core.py","lineNumber":2984,"sourceCode":"            return (cx, cy), (cx + width, cy + height)\n        raise ValueError(f\"Unsupported position: {position}\")\n\n    @staticmethod\n    def _validate_custom_values(\n        custom_values: npt.NDArray[np.float64] | list[float] | None,\n        detections: Detections,\n    ) -> None:\n        if custom_values is None:\n            if detections.confidence is None:\n                raise ValueError(\n                    \"The provided detections do not contain confidence values. \"\n                    \"Please provide `custom_values` or ensure that the detections \"\n                    \"contain confidence values (e.g. by using a different model).\"\n                )\n\n        else:\n            if not isinstance(custom_values, (np.ndarray, list)):\n                raise TypeError(\n                    \"custom_values must be either a numpy array or a list of floats.\"\n                )\n\n            if len(custom_values) != len(detections):\n                raise ValueError(\n                    \"The length of custom_values must match the number of detections.\"\n                )\n\n            if not all(0 <= value <= 1 for value in custom_values):\n                raise ValueError(\"All values in custom_values must be between 0 and 1.\")\n\n    @staticmethod\n    @deprecated(  # type: ignore[untyped-decorator]\n        target=_validate_custom_values.__func__,  # type: ignore[attr-defined]\n        deprecated_in=\"0.29.0\",\n        remove_in=\"0.32.0\",\n    )\n    def validate_custom_values(","sourceCodeStart":2966,"sourceCodeEnd":3002,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/annotators/core.py#L2966-L3002","documentation":"Raised by `PercentageBarAnnotator._validate_custom_values` when `custom_values` is neither a NumPy array nor a Python list. The API accepts only those two container types so it can validate length and value range uniformly; tuples, generators, pandas Series, or scalars are rejected with a TypeError.","triggerScenarios":"Passing `custom_values=(0.5, 0.8)` (tuple), a generator, a pandas Series, a torch tensor, or a bare float to `PercentageBarAnnotator.annotate`. Each fails the `isinstance(custom_values, (np.ndarray, list))` check.","commonSituations":"Handing over a pandas column from a dataframe-backed pipeline; passing a torch tensor in a training-loop visualization; forgetting to materialize a generator; passing a single scalar when there is exactly one detection.","solutions":["Convert to a list or NumPy array: `custom_values=list(values)`, `np.asarray(values)`, `values.tolist()`, or `tensor.cpu().numpy()`.","For a single detection, still pass a one-element container: `[0.7]`.","Keep values in 0-1 range after conversion."],"exampleFix":"# before\nannotator.annotate(scene, detections, custom_values=scores_tensor)      # torch tensor\nannotator.annotate(scene, detections, custom_values=(0.5, 0.8))          # tuple\n\n# after\nannotator.annotate(scene, detections, custom_values=scores_tensor.cpu().numpy())\nannotator.annotate(scene, detections, custom_values=[0.5, 0.8])","handlingStrategy":"type-guard","validationCode":"if not isinstance(custom_values, (np.ndarray, list)):\n    custom_values = list(custom_values)  # materialize tuples/generators/Series","typeGuard":"def is_valid_custom_values(v) -> bool:\n    return isinstance(v, (np.ndarray, list))","tryCatchPattern":null,"preventionTips":["Convert torch tensors with .cpu().numpy() and pandas objects with np.asarray at the boundary.","Wrap single scalars as one-element lists."],"tags":["annotators","type-error","validation"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}