Repository: pandas-dev/pandas
File: pandas/io/formats/format.py (Python)

Code before:
            return col_header + adjoined
        else:
            return adjoined

    def _get_column_name_list(self) -> list[Hashable]:
        names: list[Hashable] = []
        columns = self.frame.columns
        if isinstance(columns, MultiIndex):
            names.extend("" if name is None else name for name in columns.names)
        else:
            names.append("" if columns.name is None else columns.name)
        return names

    def _validate_float_format(
        self, fmt: FloatFormatType | None
    ) -> FloatFormatType | None:
        """
        Validates and processes the float_format argument.
        Converts new-style format strings to callables.
        """

        if fmt is None:
            return None

        if callable(fmt):
            return fmt

        if isinstance(fmt, str):
            if "%" in fmt:
                # Keeps old-style format strings as they are (C code handles them)
                return fmt
            else:
                try:
                    _ = fmt.format(1.0)  # Test with an arbitrary float
                    return lambda x: fmt.format(x)
                except (ValueError, KeyError, IndexError) as e:
                    raise ValueError(f"Invalid new-style format string {fmt!r}") from e

        # If fmt is neither None, nor callable, nor a successfully processed string,
        raise ValueError("float_format must be a string or callable")


class DataFrameRenderer:
    """Class for creating dataframe output in multiple formats.

    Called in pandas.core.generic.NDFrame:
        - to_csv
        - to_latex

    Called in pandas.DataFrame:
        - to_html

Review comment (suggestion):
```suggestion
        if fmt is None or callable(fmt):
            return fmt
```

Code after:
        else:
            return adjoined

    def _get_column_name_list(self) -> list[Hashable]:
        names: list[Hashable] = []
        columns = self.frame.columns
        if isinstance(columns, MultiIndex):
            names.extend("" if name is None else name for name in columns.names)
        else:
            names.append("" if columns.name is None else columns.name)
        return names

    def _validate_float_format(
        self, fmt: FloatFormatType | None
    ) -> FloatFormatType | None:
        """
        Validates and processes the float_format argument.
        Converts new-style format strings to callables.
        """
        if fmt is None or callable(fmt):
            return fmt

        if isinstance(fmt, str):
            if "%" in fmt:
                # Keeps old-style format strings as they are (C code handles them)
                return fmt
            else:
                try:
                    _ = fmt.format(1.0)  # Test with an arbitrary float
                    return fmt.format
                except (ValueError, KeyError, IndexError) as e:
                    raise ValueError(f"Invalid new-style format string {fmt!r}") from e

        raise ValueError("float_format must be a string or callable")


class DataFrameRenderer:
    """Class for creating dataframe output in multiple formats.

    Called in pandas.core.generic.NDFrame:
        - to_csv
        - to_latex

    Called in pandas.DataFrame:
        - to_html
        - to_string

    Parameters
    ----------
    fmt : DataFrameFormatter
        Formatter with the formatting options.