Skip to content

Commit 98006fc

Browse files
committed
fix(dashboard): catch single-line matplotlib artist dicts alongside a figure
The multi-line branch of the discard heuristic already caught boxplot's dict-of-Line2D repr when IPython pretty-prints it across lines, but a short dict small enough to stay on one line (e.g. a single-entry boxplot/hist result) fell into the single-line branch, which only matched bracket wrappers starting with <, (, or [ — not {. Extend the single-line case to also discard a {...} repr that references a matplotlib object.
1 parent c1798aa commit 98006fc

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/core/jupyter/jupyter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,8 @@ export function isDiscardableTextExecuteResult(
17741774
// numeric coordinate (Text(0.5, ...)), unlike other libraries' Text
17751775
const first = textPlain[0].trim();
17761776
return /^([<(\[]).*?([>)\]])$/.test(first) ||
1777-
/^Text\([-\d]/.test(first);
1777+
/^Text\([-\d]/.test(first) ||
1778+
(first.startsWith("{") && first.includes("<matplotlib."));
17781779
} else {
17791780
// multi-line reprs that are collections of matplotlib artists, e.g.
17801781
// the dict of Line2D returned by boxplot(). Only suppress when a

tests/unit/jupyter/discardable-text.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const boxplotDict = [
3131
" 'fliers': [<matplotlib.lines.Line2D at 0x17685b55010>],\n",
3232
" 'means': []}",
3333
];
34+
// A single-line dict of matplotlib artists (small enough that IPython does not
35+
// pretty-print it across lines). Unambiguous plotting noise.
36+
const singleLineDict = ["{'line': <matplotlib.lines.Line2D at 0x1407>}"];
3437
const titleText = ["Text(0.5, 1.0, 'Test')"];
3538
const axesRepr = ["<Axes: title={'center': 'Test'}>"];
3639
const line2DRepr = ["<matplotlib.lines.Line2D at 0x14071bc7e00>"];
@@ -69,6 +72,11 @@ unitTest(
6972
true,
7073
"bare Line2D repr should be discarded",
7174
);
75+
assertEquals(
76+
isDiscardableTextExecuteResult(execResult(singleLineDict), true),
77+
true,
78+
"single-line dict of matplotlib artists should be discarded",
79+
);
7280

7381
// Gate: with no image in the cell, nothing here is discarded — a cell
7482
// that only echoed these values (no figure) must keep them.

0 commit comments

Comments
 (0)