File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @e2b/code-interpreter-template ' : patch
3
+ ---
4
+
5
+ Return json on dict
Original file line number Diff line number Diff line change 1
1
import pandas
2
2
from matplotlib .pyplot import Figure
3
3
import IPython
4
- from IPython .core .formatters import BaseFormatter
4
+ from IPython .core .formatters import BaseFormatter , JSONFormatter
5
5
from traitlets .traitlets import Unicode , ObjectName
6
6
7
7
from e2b_charts import chart_figure_to_dict
@@ -48,10 +48,24 @@ def __call__(self, obj):
48
48
return super ().__call__ (obj )
49
49
50
50
51
+ class E2BDictFormatter (JSONFormatter ):
52
+ def __call__ (self , obj ):
53
+ # Figure object is for some reason removed on execution of the cell,
54
+ # so it can't be used in type_printers or with top-level import
55
+
56
+ if isinstance (obj , dict ):
57
+ return obj , {"expanded" : True }
58
+ return super ().__call__ (obj )
59
+
60
+
51
61
ip = IPython .get_ipython ()
52
62
ip .display_formatter .formatters ["e2b/data" ] = E2BDataFormatter (
53
63
parent = ip .display_formatter
54
64
)
55
65
ip .display_formatter .formatters ["e2b/chart" ] = E2BChartFormatter (
56
66
parent = ip .display_formatter
57
67
)
68
+
69
+ ip .display_formatter .formatters ["application/json" ] = E2BDictFormatter (
70
+ parent = ip .display_formatter
71
+ )
You can’t perform that action at this time.
0 commit comments