def _try_keep(k):
            """If all the values for a key `k` are the same in this group, we can keep it."""
            if k not in df.columns:
                return  # pragma: no cover
            vals = df[k].unique()
            if len(vals) == 1:
                ret[k] = vals[0]
            else:  # pragma: no cover
                raise AssertionError(
                    f"When computing per-cycle-depth fidelity, multiple "
                    f"values for {k} were grouped together: {vals}"
                )
If all the values for a key `k` are the same in this group, we can keep it.
cirq-core/cirq/experiments/xeb_fitting.py