def write_golden(
        self,
        golden_path: Union[str, Path],
        data: Union[serial_utils.JSON, pd.DataFrame],
    ) -> None:
        """If writing golden file is enabled, write the golden file `path` with
        `data` and raise exception indicating so.

        If not writing golden file, does nothing.

        Args:
            golden_path: The path to the golden file to write. Format is
                determined by suffix.

            data: The data to write to the golden file.
        """
        if not self.writing_golden():
            return

        golden_path = Path(golden_path)

        if golden_path.suffix == ".json":
            writer = functools.partial(json.dump, indent=2, sort_keys=True)
        elif golden_path.suffix == ".yaml":
            writer = functools.partial(yaml.dump, sort_keys=True)
        elif golden_path.suffix == ".csv":
            writer = lambda data, f: data.to_csv(f)
        elif golden_path.suffix == ".parquet":
            writer = lambda data, f: data.to_parquet(f)
        else:
            raise ValueError(f"Unknown file extension {golden_path.suffix}.")

        with golden_path.open("w") as f:
            writer(data, f)

        self.fail(f"Golden file {golden_path} written.")
If writing golden file is enabled, write the golden file `path` with
        `data` and raise exception indicating so.

        If not writing golden file, does nothing.

        Args:
            golden_path: The path to the golden file to write. Format is
                determined by suffix.

            data: The data to write to the golden file.
        
tests/test.py