1
1
""" self-contained to write legacy pickle files """
2
2
3
+ def _create_sp_series ():
4
+
5
+ import numpy as np
6
+ from pandas import bdate_range , SparseSeries
7
+
8
+ nan = np .nan
9
+
10
+ # nan-based
11
+ arr = np .arange (15 , dtype = float )
12
+ index = np .arange (15 )
13
+ arr [7 :12 ] = nan
14
+ arr [- 1 :] = nan
15
+
16
+ date_index = bdate_range ('1/1/2011' , periods = len (index ))
17
+ bseries = SparseSeries (arr , index = index , kind = 'block' )
18
+ bseries .name = 'bseries'
19
+ return bseries
20
+
21
+ def _create_sp_frame ():
22
+ import numpy as np
23
+ from pandas import bdate_range , SparseDataFrame
24
+
25
+ nan = np .nan
26
+
27
+ data = {'A' : [nan , nan , nan , 0 , 1 , 2 , 3 , 4 , 5 , 6 ],
28
+ 'B' : [0 , 1 , 2 , nan , nan , nan , 3 , 4 , 5 , 6 ],
29
+ 'C' : np .arange (10 ),
30
+ 'D' : [0 , 1 , 2 , 3 , 4 , 5 , nan , nan , nan , nan ]}
31
+
32
+ dates = bdate_range ('1/1/2011' , periods = 10 )
33
+ return SparseDataFrame (data , index = dates )
34
+
3
35
def create_data ():
4
36
""" create the pickle data """
5
37
@@ -8,7 +40,8 @@ def create_data():
8
40
from pandas import (Series ,DataFrame ,Panel ,
9
41
SparseSeries ,SparseDataFrame ,SparsePanel ,
10
42
Index ,MultiIndex ,PeriodIndex ,
11
- date_range ,Timestamp )
43
+ date_range ,bdate_range ,Timestamp )
44
+ nan = np .nan
12
45
13
46
data = {
14
47
'A' : [0. , 1. , 2. , 3. , np .nan ],
@@ -18,17 +51,29 @@ def create_data():
18
51
'E' : [0. , 1 , Timestamp ('20100101' ),'foo' ,2. ],
19
52
}
20
53
54
+ index = dict (int = Index (np .arange (10 )),
55
+ date = date_range ('20130101' ,periods = 10 ))
56
+ mi = dict (reg = MultiIndex .from_tuples (zip ([['bar' , 'bar' , 'baz' , 'baz' , 'foo' , 'foo' , 'qux' , 'qux' ],
57
+ ['one' , 'two' , 'one' , 'two' , 'one' , 'two' , 'one' , 'two' ]]),
58
+ names = ['first' , 'second' ]))
21
59
series = dict (float = Series (data ['A' ]),
22
60
int = Series (data ['B' ]),
23
61
mixed = Series (data ['E' ]))
24
62
frame = dict (float = DataFrame (dict (A = series ['float' ], B = series ['float' ] + 1 )),
25
63
int = DataFrame (dict (A = series ['int' ] , B = series ['int' ] + 1 )),
26
64
mixed = DataFrame (dict ([ (k ,data [k ]) for k in ['A' ,'B' ,'C' ,'D' ]])))
27
65
panel = dict (float = Panel (dict (ItemA = frame ['float' ], ItemB = frame ['float' ]+ 1 )))
28
-
66
+
67
+
68
+
29
69
return dict ( series = series ,
30
70
frame = frame ,
31
- panel = panel )
71
+ panel = panel ,
72
+ index = index ,
73
+ mi = mi ,
74
+ sp_series = dict (float = _create_sp_series ()),
75
+ sp_frame = dict (float = _create_sp_frame ())
76
+ )
32
77
33
78
def write_legacy_pickles ():
34
79
@@ -43,7 +88,7 @@ def write_legacy_pickles():
43
88
import platform as pl
44
89
import cPickle as pickle
45
90
46
- print "This script generates a pickle file for the current arch, system, and python version"
91
+ print ( "This script generates a pickle file for the current arch, system, and python version" )
47
92
48
93
base_dir , _ = os .path .split (os .path .abspath (__file__ ))
49
94
base_dir = os .path .join (base_dir ,'data/legacy_pickle' )
@@ -68,7 +113,7 @@ def write_legacy_pickles():
68
113
pickle .dump (create_data (),fh ,pickle .HIGHEST_PROTOCOL )
69
114
fh .close ()
70
115
71
- print "created pickle file: %s" % pth
116
+ print ( "created pickle file: %s" % pth )
72
117
73
118
if __name__ == '__main__' :
74
119
write_legacy_pickles ()
0 commit comments