Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabulator: don't attempt to set text_align on Bokeh formatters that don't support it #6010

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,3 +2148,15 @@ def test_bokeh_formatter_index_with_no_textalign():
table = Tabulator(df, formatters={"A": index_format})
serve_and_request(table)
wait_until(lambda: bool(table._models))

@pytest.mark.parametrize('text_align', [{"A": "center"}, "center"], ids=["dict", "str"])
def test_bokeh_formatter_column_with_no_textalign_but_text_align_set(document, comm, text_align):
df = pd.DataFrame({"A": [1, 2, 3]})
table = Tabulator(
df,
formatters=dict(A=HTMLTemplateFormatter(template='<b><%= value %>"></b>')),
text_align=text_align,
)

model = table.get_root(document, comm)
assert model.configuration['columns'][1]['hozAlign'] == 'center'
6 changes: 4 additions & 2 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ def _get_column_definitions(self, col_names: List[str], df: pd.DataFrame) -> Lis
else:
default_text_align = True

if isinstance(self.text_align, str):
if not hasattr(formatter, 'text_align'):
pass
elif isinstance(self.text_align, str):
formatter.text_align = self.text_align
if not default_text_align:
msg = f"The 'text_align' in Tabulator.formatters[{col!r}] is overridden by Tabulator.text_align"
Expand All @@ -234,7 +236,7 @@ def _get_column_definitions(self, col_names: List[str], df: pd.DataFrame) -> Lis
if not default_text_align:
msg = f"The 'text_align' in Tabulator.formatters[{col!r}] is overridden by Tabulator.text_align[{col!r}]"
warn(msg, RuntimeWarning)
elif col in self.indexes and hasattr(formatter, "text_align"):
elif col in self.indexes:
formatter.text_align = 'left'

if isinstance(self.widths, int):
Expand Down
Loading