def proper_repr(value: Any) -> str:
    """Overrides sympy and numpy returning repr strings that don't parse."""

    if isinstance(value, sympy.Basic):
        # HACK: work around https://github.com/sympy/sympy/issues/16074
        fixed_tokens = [
            'Symbol',
            'pi',
            'Mul',
            'Pow',
            'Add',
            'Mod',
            'Integer',
            'Float',
            'Rational',
            'GreaterThan',
            'StrictGreaterThan',
            'LessThan',
            'StrictLessThan',
            'Equality',
            'Unequality',
            'And',
            'Or',
            'Not',
            'Xor',
            'Indexed',
            'IndexedBase',
        ]

        class Printer(sympy.printing.repr.ReprPrinter):
            def _print(self, expr, **kwargs):
                s = super()._print(expr, **kwargs)
                if any(s.startswith(t) for t in fixed_tokens):
                    return 'sympy.' + s
                return s

        return Printer().doprint(value)

    if isinstance(value, np.ndarray):
        return f'np.array({value.tolist()!r}, dtype=np.{value.dtype!r})'

    if isinstance(value, pd.MultiIndex):
        return f'pd.MultiIndex.from_tuples({repr(list(value))}, names={repr(list(value.names))})'

    if isinstance(value, pd.Index):
        return (
            f'pd.Index({repr(list(value))}, '
            f'name={repr(value.name)}, '
            f'dtype={repr(str(value.dtype))})'
        )

    if isinstance(value, pd.DataFrame):
        cols = [value[col].tolist() for col in value.columns]
        rows = list(zip(*cols))
        return (
            f'pd.DataFrame('
            f'\n    columns={proper_repr(value.columns)}, '
            f'\n    index={proper_repr(value.index)}, '
            f'\n    data={repr(rows)}'
            f'\n)'
        )

    if isinstance(value, dict):
        return '{' + ','.join(f"{proper_repr(k)}: {proper_repr(v)}" for k, v in value.items()) + '}'

    if hasattr(value, "__qualname__"):
        return f"{value.__module__}.{value.__qualname__}"

    if isinstance(value, np.number):
        return str(value)

    return repr(value)
Overrides sympy and numpy returning repr strings that don't parse.
cirq-core/cirq/_compat.py