-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework table implementation to allow granular control of tabular form…
…atting
- Loading branch information
krande
committed
Sep 14, 2021
1 parent
bc11923
commit bb863c3
Showing
10 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{__my_table__}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{__my_table_2__}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
linkReferences: true | ||
nameInLink: true | ||
figPrefix: "Figure" | ||
tblPrefix: "Table" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from dataclasses import dataclass | ||
import pandas as pd | ||
from .formatting import TableFormat | ||
|
||
|
||
@dataclass | ||
class Table: | ||
name: str | ||
df: pd.DataFrame | ||
caption: str | ||
format: TableFormat = TableFormat() | ||
|
||
def to_markdown(self, include_name_in_cell=False): | ||
df = self.df.copy() | ||
if include_name_in_cell: | ||
col_name = df.columns[0] | ||
df.iloc[0, df.columns.get_loc(col_name)] = self.name | ||
tbl_str = df.to_markdown(index=False, tablefmt="grid") | ||
tbl_str += f"\nTable: {self.caption}" | ||
return tbl_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import unittest | ||
from paradoc import OneDoc | ||
from paradoc.formatting import TableFormat | ||
import pandas as pd | ||
|
||
from common import files_dir, test_dir | ||
|
||
|
||
class TableTests(unittest.TestCase): | ||
def test_table(self): | ||
report_dir = files_dir / "doc_table" | ||
one = OneDoc(report_dir, work_dir=test_dir / "doc_table") | ||
df = pd.DataFrame([(0, 0), (1, 2)], columns=["a", "b"]) | ||
|
||
one.add_table("my_table", df, "A basic table") | ||
one.add_table("my_table_2", df, "A slightly smaller table", TableFormat(font_size=8)) | ||
|
||
one.compile("TableDoc") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |