{"record":{"id":"3724b4ec5324746b","repo":"tensorflow/models","slug":"the-slicing-spec-must-be-a-non-empty-dictionary","errorCode":null,"errorMessage":"The slicing spec must be a non-empty dictionary.","messagePattern":"The slicing spec must be a non-empty dictionary\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/metrics/sliced_metric.py","lineNumber":92,"sourceCode":"\n    Args:\n      metric: A `tf_keras.metrics.Metric` instance.\n      slicing_spec: A dictionary that maps from string slice names, to one of\n        integer, boolean, or string slicing values.\n      slicing_feature_dtype: The expected dtype of the slicing feature. The\n        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","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/metrics/sliced_metric.py#L74-L110","documentation":"Error \"The slicing spec must be a non-empty dictionary.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/metrics/sliced_metric.py:92 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"}