Commit 0eecccd
authored
fix(datasets): avoid exponential blow-up of nested struct sample values (#9506)
## Summary
`NarwhalsTableManager.get_sample_values` recursively re-stringified
nested list/dict cells, causing each ancestor level to re-escape the
children's repr. For deeply nested polars `Struct`/`List` columns this
scaled ~8× per depth and produced multi-GB strings that hung the browser
when the dataframe was registered as a dataset.
Replace the recursion with one `json.dumps` pass, preserving the
`Enum.name`-at-any-depth contract via a `default=` callback. Scalar
paths are unchanged.
Fixes #9378.
## Test plan
- [x] New tests in `tests/_plugins/ui/_impl/tables/test_narwhals.py`
cover: bounded time/size at nesting depth 8, JSON-shaped output,
non-JSON leaf (datetime) embedded in a struct.
- [x] `uv run --group test pytest tests/_plugins/ui/_impl/tables/` — 468
passed.
- [x] `make py-check` clean.
- [x] Manual: register a polars df with depth-8 nested struct via a
top-level variable; browser no longer hangs and SQL column hover shows a
readable JSON preview.1 parent af0556c commit 0eecccd
2 files changed
Lines changed: 85 additions & 7 deletions
File tree
- marimo/_plugins/ui/_impl/tables
- tests/_plugins/ui/_impl/tables
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
698 | 700 | | |
699 | 701 | | |
700 | 702 | | |
701 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
702 | 708 | | |
703 | 709 | | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 710 | + | |
709 | 711 | | |
710 | | - | |
| 712 | + | |
711 | 713 | | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
712 | 719 | | |
713 | 720 | | |
714 | 721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1535 | 1535 | | |
1536 | 1536 | | |
1537 | 1537 | | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
1538 | 1609 | | |
1539 | 1610 | | |
1540 | 1611 | | |
| |||
0 commit comments