Skip to content

Commit

Permalink
support non-string column names for AG Grid (fixes #1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Sep 25, 2023
1 parent 5d48a79 commit 23cd363
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nicegui/elements/aggrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_aggrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ 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('/')
screen.should_contain('Alice')
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):
Expand Down

0 comments on commit 23cd363

Please sign in to comment.