@@ -8,9 +8,12 @@ Property Name As %String;
8
8
/// Variable Class
9
9
Property Type As %String ;
10
10
11
- /// Variable repr
11
+ /// Variable repr serialization
12
12
Property Value As %VarString ;
13
13
14
+ /// Variable pickle serialization
15
+ Property Pickle As %VarString ;
16
+
14
17
/// Variable JSON serialization
15
18
Property JSON As %VarString ;
16
19
@@ -25,22 +28,24 @@ ClassMethod SaveVariable(name As %String = "", Output variable As isc.py.data.Va
25
28
quit :repr =" " $$$ERROR($$$GeneralError, $$$FormatText(" Variable %1 is empty or initialized" , name ))
26
29
27
30
set type = ##class (isc.py.Callout ).SimpleString (" zzztype=type(" _name _" ).__name__" , " zzztype" )
28
- do ##class (isc.py.Callout ).SimpleString (" import json;" )
31
+ do ##class (isc.py.Callout ).SimpleString (" import json, pickle;" )
32
+
29
33
if type = " DataFrame" {
30
- //set json = ##class(isc.py.Callout).SimpleString("zzzjson=json.dumps([list("_name_".index), list("_name_"), "_name_".values.tolist()])", "zzzjson")
31
34
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
35
} else {
34
36
set json = ##class (isc.py.Callout ).SimpleString (" zzzjson=json.dumps(" _name _ " )" , " zzzjson" )
35
37
}
36
38
39
+ set pickle = ##class (isc.py.Callout ).SimpleString (" zzzjson=pickle.dumps(" _name _ " )" , " zzzjson" )
40
+
37
41
38
42
do ##class (isc.py.Callout ).SimpleString (" del zzztype, zzzjson" )
39
43
40
44
set variable = ..%New ()
41
45
set variable .Name = name
42
46
set variable .Value = repr
43
47
set variable .Type = type
48
+ set variable .Pickle = pickle
44
49
set variable .JSON = json
45
50
set sc = variable .%Save ()
46
51
@@ -56,20 +61,15 @@ Method Display(indent As %String = "")
56
61
If $l (..Value )<=limit {
57
62
Write indent , " Value: " , ..Value , !
58
63
} Else {
59
- Write indent , " Value (truncated): " , $e (..Value ,1 ,limit ), !
64
+ Write indent , " Value (truncated): " , $replace ( $ e (..Value ,1 ,limit ), $c ( 10 ), $c ( 13 , 10 ) ), !
60
65
}
61
66
write !
62
67
}
63
68
64
69
/// Restore variable for disk.
65
70
Method Restore (context As isc .py .data .Context )
66
71
{
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
- }
72
+ do ##class (isc.py.Callout ).SimpleString (..Name _ " =pickle.loads(" _ ..Pickle _ " )" )
73
73
}
74
74
75
75
Storage Default
@@ -90,6 +90,9 @@ Storage Default
90
90
<Value name =" 5" >
91
91
<Value >JSON </Value >
92
92
</Value >
93
+ <Value name =" 6" >
94
+ <Value >Pickle </Value >
95
+ </Value >
93
96
</Data >
94
97
<DataLocation >^isc .py .data .VarableD </DataLocation >
95
98
<DefaultData >VarableDefaultData </DefaultData >
0 commit comments