Skip to content

Commit b35163c

Browse files
committed
Restore dataframes
1 parent 286f48a commit b35163c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

isc/py/data/Context.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ Method Restore(verbose As %Boolean = {$$$NO}, clear As %Boolean = {$$$NO}) As %S
130130

131131
// Restoring variables
132132
for i=1:1:..Variables.Count() {
133+
#dim variable As isc.py.data.Varable
133134
set variable = ..Variables.GetAt(i)
134-
do variable.Restore()
135+
continue:$e(variable.Value,1)="<"
136+
do variable.Restore($this)
135137
}
136138

137139
do:verbose ..Display()

isc/py/data/Varable.cls

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ ClassMethod SaveVariable(name As %String = "", Output variable As isc.py.data.Va
2626

2727
set type = ##class(isc.py.Callout).SimpleString("zzztype=type("_name_").__name__", "zzztype")
2828
do ##class(isc.py.Callout).SimpleString("import json;")
29-
set json = ##class(isc.py.Callout).SimpleString("zzzjson=json.dumps(r)", "zzzjson")
29+
if type = "DataFrame" {
30+
//set json = ##class(isc.py.Callout).SimpleString("zzzjson=json.dumps([list("_name_".index), list("_name_"), "_name_".values.tolist()])", "zzzjson")
31+
set json = ##class(isc.py.Callout).SimpleString("zzzjson=" _name _ ".to_json()", "zzzjson")
32+
set repr = ##class(isc.py.Callout).SimpleString("zzzjson=" _name _ ".to_dict()", "zzzjson")
33+
} else {
34+
set json = ##class(isc.py.Callout).SimpleString("zzzjson=json.dumps(" _name _ ")", "zzzjson")
35+
}
36+
37+
3038
do ##class(isc.py.Callout).SimpleString("del zzztype, zzzjson")
3139

3240
set variable = ..%New()
@@ -54,9 +62,14 @@ Method Display(indent As %String = "")
5462
}
5563

5664
/// Restore variable for disk.
57-
Method Restore()
65+
Method Restore(context As isc.py.data.Context)
5866
{
59-
do ##class(isc.py.Callout).SimpleString(..Name _ "=" _ ..Value)
67+
if ..Type = "DataFrame" {
68+
set pandas = context.Modules.GetAt("pandas")
69+
do ##class(isc.py.Callout).SimpleString(..Name _ "=" _ pandas _".DataFrame.from_dict(" _ ..Value _ ")")
70+
} else {
71+
do ##class(isc.py.Callout).SimpleString(..Name _ "=" _ ..Value)
72+
}
6073
}
6174

6275
Storage Default

0 commit comments

Comments
 (0)