From 23cd363f8e48bd87608e52aa652b716c03b0e0f9 Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Mon, 25 Sep 2023 17:57:23 +0200 Subject: [PATCH] support non-string column names for AG Grid (fixes #1665) --- nicegui/elements/aggrid.py | 2 +- tests/test_aggrid.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nicegui/elements/aggrid.py b/nicegui/elements/aggrid.py index 70c561fe1..0389d8182 100644 --- a/nicegui/elements/aggrid.py +++ b/nicegui/elements/aggrid.py @@ -52,7 +52,7 @@ def from_pandas(df: pd.DataFrame, *, :return: AG Grid element """ return AgGrid({ - 'columnDefs': [{'field': col} for col in df.columns], + 'columnDefs': [{'field': str(col)} for col in df.columns], 'rowData': df.to_dict('records'), 'suppressDotNotation': True, **options, diff --git a/tests/test_aggrid.py b/tests/test_aggrid.py index e6546fb3e..27b2e11e1 100644 --- a/tests/test_aggrid.py +++ b/tests/test_aggrid.py @@ -164,7 +164,7 @@ def replace(): def test_create_from_pandas(screen: Screen): - df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [18, 21]}) + df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [18, 21], 42: 'answer'}) ui.aggrid.from_pandas(df) screen.open('/') @@ -172,6 +172,8 @@ def test_create_from_pandas(screen: Screen): screen.should_contain('Bob') screen.should_contain('18') screen.should_contain('21') + screen.should_contain('42') + screen.should_contain('answer') def test_create_dynamically(screen: Screen):