Skip to content

Commit 63e5e18

Browse files
committed
Fix deserialization of empty grids
Signed-off-by: martinRenou <[email protected]>
1 parent 21db0ce commit 63e5e18

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

js/datagrid.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,22 @@ function serialize_data(data: DataSource, manager: any): any {
8484
function deserialize_data(data: any, manager: any): DataSource {
8585
const deserialized_data: any = {};
8686
for (const column of Object.keys(data.data)) {
87+
deserialized_data[column] = [];
88+
89+
if (Array.isArray(data.data[column])) {
90+
deserialized_data[column] = data.data[column];
91+
continue;
92+
}
93+
8794
if (data.data[column].type == 'raw') {
8895
deserialized_data[column] = unpack_raw_data(data.data[column].value);
8996
} else {
90-
deserialized_data[column] = array_or_json_serializer.deserialize(
91-
data.data[column],
92-
manager,
93-
);
97+
if (data.data[column].value.length !== 0) {
98+
deserialized_data[column] = array_or_json_serializer.deserialize(
99+
data.data[column],
100+
manager,
101+
);
102+
}
94103
}
95104
}
96105
return new DataSource(deserialized_data, data.fields, data.schema, true);
4.09 KB
Loading
4.13 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "c8271791-1c8f-4b79-b105-f57576533aaa",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from ipydatagrid import DataGrid, TextRenderer, BarRenderer, Expr, ImageRenderer\n",
11+
"\n",
12+
"import pandas as pd\n",
13+
"\n",
14+
"columns = [\"a\", \"b\", \"c\"]\n",
15+
"\n",
16+
"df = pd.DataFrame(dict(zip(columns, len(columns) * [[]])))\n",
17+
"DataGrid(df)"
18+
]
19+
}
20+
],
21+
"metadata": {
22+
"kernelspec": {
23+
"display_name": "Python 3 (ipykernel)",
24+
"language": "python",
25+
"name": "python3"
26+
},
27+
"language_info": {
28+
"codemirror_mode": {
29+
"name": "ipython",
30+
"version": 3
31+
},
32+
"file_extension": ".py",
33+
"mimetype": "text/x-python",
34+
"name": "python",
35+
"nbconvert_exporter": "python",
36+
"pygments_lexer": "ipython3",
37+
"version": "3.12.3"
38+
}
39+
},
40+
"nbformat": 4,
41+
"nbformat_minor": 5
42+
}

0 commit comments

Comments
 (0)