Skip to content

Table

TableRenderer

Bases: Renderer

Renderer for tables.

Source code in dvc_render/table.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class TableRenderer(Renderer):
    """Renderer for tables."""

    TYPE = "table"
    DIV = """
        <div id="{id}" style="text-align: center; padding: 10x">
            <p>{id}</p>
            <div style="display: flex;justify-content: center;">
                {partial}
            </div>
        </div>"""

    SCRIPTS = ""

    EXTENSIONS = {".yml", ".yaml", ".json"}

    @classmethod
    def to_tabulate(cls, datapoints, tablefmt):
        """Convert datapoints to tabulate format"""
        if tabulate is None:
            raise ImportError(f"{cls.__name__} requires `tabulate`.")  # noqa: TRY003
        data = list_dict_to_dict_list(datapoints)
        return tabulate(data, headers="keys", tablefmt=tablefmt)

    def partial_html(self, **kwargs) -> str:  # noqa: ARG002
        return self.to_tabulate(self.datapoints, tablefmt="html")

    def generate_markdown(self, report_path=None) -> str:  # noqa: ARG002
        table = self.to_tabulate(self.datapoints, tablefmt="github")
        return f"\n{self.name}\n\n{table}"

to_tabulate(datapoints, tablefmt) classmethod

Convert datapoints to tabulate format

Source code in dvc_render/table.py
26
27
28
29
30
31
32
@classmethod
def to_tabulate(cls, datapoints, tablefmt):
    """Convert datapoints to tabulate format"""
    if tabulate is None:
        raise ImportError(f"{cls.__name__} requires `tabulate`.")  # noqa: TRY003
    data = list_dict_to_dict_list(datapoints)
    return tabulate(data, headers="keys", tablefmt=tablefmt)