tensorflow/models · error · ValueError
All slicing values in the slicing spec must be one of `int`,
Error message
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))}. What it means
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.
Source
Thrown at official/recommendation/uplift/metrics/sliced_metric.py:98
values in the slicing spec are casted to this type if passed. If None,
the dtype of the slicing feature is inferred based on the values in the
slicing spec.
name: The name of the wrapper metric. Defaults to `sliced_{metric.name}`.
Raises:
A ValueError if `slicing_spec` is empty, contains duplicate slicing
values, or has slicing values of different types.
"""
super().__init__(name=name or f"sliced_{metric.name}", dtype=metric.dtype)
if not slicing_spec:
raise ValueError("The slicing spec must be a non-empty dictionary.")
slice_names, slicing_values = zip(*slicing_spec.items())
if not isinstance(slicing_values[0], (int, bool, str)) or not all(
isinstance(k, type(slicing_values[0])) for k in slicing_values
):
raise ValueError(
"All slicing values in the slicing spec must be one of `int`, "
"`bool`, or `str`, and all values must have the same type. "
f"Got types: {list(map(type, slicing_values))}."
)
if len(slicing_values) > len(set(slicing_values)):
raise ValueError(
"The slicing values passed to the slicing spec must be unique. Got "
f"{slicing_values}."
)
# TODO(b/276811843): Look into validating whether `metric` accepts
# `sample_weights` in its `update_state` method.
# Instance fully owns a deep copy of the metric.
self._metric = copy.deepcopy(metric)
self._slice_names = list(slice_names)
self._slicing_values = list(slicing_values)View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/uplift/metrics/sliced_metric.py:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/5ad19ab9e6601651.
Report an issue: GitHub.