-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Kuethe
committed
Sep 21, 2024
1 parent
6853e98
commit f30bde2
Showing
7 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
from pandas import read_csv | ||
|
||
def titanic(): | ||
pass |
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,78 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal, Union, Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, field_validator | ||
|
||
class TabulatorOptions(BaseModel): | ||
"""Tabulator options. | ||
Attributes: | ||
index (str, optional): The index of the table. Defaults to `id`. | ||
header_visible (bool, optional): Whether to display the header of the table. Defaults to `True`. | ||
movable_rows (bool, optional): Whether rows are movable or not. Defaults to `False`. | ||
group_by: Columns to group by. Defaults to `None`. | ||
height (int, optional): Height in px. Defaults to `300`. | ||
pagination (bool, optional): Whether to enable pagination. Defaults to `False`. | ||
pagination_counter (str, optional): Whether to display counted rows in footer. Defaults to `rows`. | ||
pagination_add_row: Where to add rows when pagination is enabled. Defaults to `page`. | ||
selectable_rows: Whether a row is selectable. An integer value sets the maximum number of rows, that can be selected. | ||
If set to `highlight`, rows do not change state when clicked. Defaults to `highlight`. | ||
columns (list, optional): Columns configuration. Defaults to `None`, | ||
which means that the default configuration is used. | ||
layout: The layout of the table. Defaults to `fitColumns`. | ||
add_row_pos: Where to add rows. Defaults to `bottom`. | ||
frozen_rows (int, optional): Number of frozen rows. Defaults to `Ǹone`. | ||
row_height: Fixed height of rows. Defaults to `None`. | ||
history (bool, optional): Whether to enable history. Must be set if `undo` and `redo` is used. Defaults to `False`. | ||
Note: | ||
See [Tabulator Setup Options](https://tabulator.info/docs/5.5/options) for details. | ||
""" | ||
|
||
index: str = "id" | ||
header_visible: Optional[bool] = Field(True, serialization_alias="headerVisible") | ||
movable_rows: Optional[bool] = Field(False, serialization_alias="movableRows") | ||
group_by: Union[str, list, None] = Field(None, serialization_alias="groupBy") | ||
height: Union[int, str, None] = None | ||
pagination: Optional[bool] = False | ||
pagination_counter: str = Field("rows", serialization_alias="paginationCounter") | ||
pagination_add_row: Literal["page", "table"] = Field( | ||
"page", serialization_alias="paginationAddRow" | ||
) | ||
selectable_rows: Union[str, bool, int] = Field( | ||
"highlight", serialization_alias="selectableRows" | ||
) | ||
columns: Optional[list] = None | ||
layout: Literal[ | ||
"fitData", "fitDataFill", "fitDataStretch", "fitDataTable", "fitColumns" | ||
] = "fitColumns" | ||
add_row_pos: Literal["bottom", "top"] = Field( | ||
"bottom", serialization_alias="addRowPos" | ||
) | ||
frozen_rows: Optional[int] = Field(None, serialization_alias="frozenRows") | ||
row_height: Optional[int] = Field(None, serialization_alias="rowHeight") | ||
resizable_column_fit: Optional[bool] = Field(False, serialization_alias="resizableColumnFit") | ||
history: Optional[bool] = False | ||
|
||
# New features to be added in the next release | ||
""" | ||
responsiveLayout: str = "hide" | ||
columnDefaults: dict = {"tooltip": True} | ||
""" | ||
|
||
model_config = ConfigDict( | ||
validate_assignment=True, | ||
extra="allow", | ||
# use_enum_values=True | ||
) | ||
|
||
@field_validator("height") | ||
def validate_height(cls, v): | ||
if isinstance(v, int): | ||
return f"{v}px" | ||
|
||
return v | ||
|
||
def to_dict(self) -> dict: | ||
return self.model_dump(by_alias=True, exclude_none=True) |
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,7 @@ | ||
import pytest | ||
import pandas as pd | ||
|
||
@pytest.fixture | ||
def persons(): | ||
data = [["Peter", 10, 10.5], ["Hans", 12, 13.7]] | ||
return pd.DataFrame(data, columns=["Name", "Age", "JustANumber"]) |
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,2 @@ | ||
def test_tabulator_columns(persons): | ||
print(persons) |