{"record":{"id":"5ad19ab9e6601651","repo":"tensorflow/models","slug":"all-slicing-values-in-the-slicing-spec-must-be-one","errorCode":null,"errorMessage":"All slicing values in the slicing spec must be one of `int`, `bool`, or `str`, and all values must have the same type. Got types: {list(map(type, slicing_values))}.","messagePattern":"All slicing values in the slicing spec must be one of `int`, `bool`, or `str`, and all values must have the same type\\. Got types: (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/sliced_metric.py","lineNumber":98,"sourceCode":"        values in the slicing spec are casted to this type if passed. If None,\n        the dtype of the slicing feature is inferred based on the values in the\n        slicing spec.\n      name: The name of the wrapper metric. Defaults to `sliced_{metric.name}`.\n\n    Raises:\n      A ValueError if `slicing_spec` is empty, contains duplicate slicing\n      values, or has slicing values of different types.\n    \"\"\"\n    super().__init__(name=name or f\"sliced_{metric.name}\", dtype=metric.dtype)\n\n    if not slicing_spec:\n      raise ValueError(\"The slicing spec must be a non-empty dictionary.\")\n\n    slice_names, slicing_values = zip(*slicing_spec.items())\n    if not isinstance(slicing_values[0], (int, bool, str)) or not all(\n        isinstance(k, type(slicing_values[0])) for k in slicing_values\n    ):\n      raise ValueError(\n          \"All slicing values in the slicing spec must be one of `int`, \"\n          \"`bool`, or `str`, and all values must have the same type. \"\n          f\"Got types: {list(map(type, slicing_values))}.\"\n      )\n\n    if len(slicing_values) > len(set(slicing_values)):\n      raise ValueError(\n          \"The slicing values passed to the slicing spec must be unique. Got \"\n          f\"{slicing_values}.\"\n      )\n\n    # TODO(b/276811843): Look into validating whether `metric` accepts\n    # `sample_weights` in its `update_state` method.\n\n    # Instance fully owns a deep copy of the metric.\n    self._metric = copy.deepcopy(metric)\n    self._slice_names = list(slice_names)\n    self._slicing_values = list(slicing_values)","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/sliced_metric.py#L80-L116","documentation":"Error \"All slicing values in the slicing spec must be one of `int`, `bool`, or `str`, and all values must have the same type. Got types: {list(map(type, slicing_values))}.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/sliced_metric.py:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}