jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
580 stars 51 forks source link

Serialization: convert tuples to strings #298

Closed ibdafna closed 2 years ago

ibdafna commented 2 years ago

Signed-off-by: Itay Dafna idafna@seas.upenn.edu

The following code triggers an exception when jupyter_client>=7 is used:

import pandas as pd
from ipydatagrid import DataGrid

col_names = [('Parent Column', 'SubCol 1'), ('Parent Column', 'SubCol 2')]
df = pd.DataFrame(data={i: [1, 2, 3] for i in col_names},
                  columns=col_names)

grid = DataGrid(df, layout={'height': '200px'})
grid

col_widths = {
    ('Parent Column', 'SubCol 1'): 100
}

grid.column_widths = col_widths

This is due to the serialization logic change where tuples are no longer implicitly converted to strings. Similar issue shown in #274

This PR adds a fix such that tuples passed as traitlet keys in dictionaries are explicitly converted to strings at source.

ibdafna commented 2 years ago

@martinRenou