1
1
#!/usr/env/bin python
2
2
3
- """ self-contained to write legacy storage (pickle/msgpack) files """
3
+ """
4
+ self-contained to write legacy storage (pickle/msgpack) files
5
+
6
+ To use this script. Create an environment where you want
7
+ generate pickles, say its for 0.18.1, with your pandas clone
8
+ in ~/pandas
9
+
10
+ . activate pandas_0.18.1
11
+ cd ~/
12
+
13
+ $ python pandas/pandas/tests/io/generate_legacy_storage_files.py \
14
+ pandas/pandas/tests/io/data/legacy_pickle/0.18.1/ pickle
15
+
16
+ This script generates a storage file for the current arch, system,
17
+ and python version
18
+ pandas version: 0.18.1
19
+ output dir : pandas/pandas/tests/io/data/legacy_pickle/0.18.1/
20
+ storage format: pickle
21
+ created pickle file: 0.18.1_x86_64_darwin_3.5.2.pickle
22
+
23
+ The idea here is you are using the *current* version of the
24
+ generate_legacy_storage_files with an *older* version of pandas to
25
+ generate a pickle file. We will then check this file into a current
26
+ branch, and test using test_pickle.py. This will load the *older*
27
+ pickles and test versus the current data that is generated
28
+ (with master). These are then compared.
29
+
30
+ If we have cases where we changed the signature (e.g. we renamed
31
+ offset -> freq in Timestamp). Then we have to conditionally execute
32
+ in the generate_legacy_storage_files.py to make it
33
+ run under the older AND the newer version.
34
+
35
+ """
36
+
4
37
from __future__ import print_function
5
38
from warnings import catch_warnings
6
39
from distutils .version import LooseVersion
9
42
Index , MultiIndex , bdate_range , to_msgpack ,
10
43
date_range , period_range ,
11
44
Timestamp , NaT , Categorical , Period )
45
+ from pandas .tseries .offsets import (
46
+ DateOffset , Hour , Minute , Day ,
47
+ MonthBegin , MonthEnd , YearBegin ,
48
+ YearEnd , Week ,
49
+ QuarterBegin , QuarterEnd )
12
50
from pandas .compat import u
13
51
import os
14
52
import sys
@@ -151,10 +189,28 @@ def create_data():
151
189
152
190
timestamp = dict (normal = Timestamp ('2011-01-01' ),
153
191
nat = NaT ,
154
- tz = Timestamp ('2011-01-01' , tz = 'US/Eastern' ),
155
- freq = Timestamp ('2011-01-01' , freq = 'D' ),
156
- both = Timestamp ('2011-01-01' , tz = 'Asia/Tokyo' ,
157
- freq = 'M' ))
192
+ tz = Timestamp ('2011-01-01' , tz = 'US/Eastern' ))
193
+
194
+ if _loose_version < '0.19.2' :
195
+ timestamp ['freq' ] = Timestamp ('2011-01-01' , offset = 'D' )
196
+ timestamp ['both' ] = Timestamp ('2011-01-01' , tz = 'Asia/Tokyo' ,
197
+ offset = 'M' )
198
+ else :
199
+ timestamp ['freq' ] = Timestamp ('2011-01-01' , freq = 'D' )
200
+ timestamp ['both' ] = Timestamp ('2011-01-01' , tz = 'Asia/Tokyo' ,
201
+ freq = 'M' )
202
+
203
+ off = {'DateOffset' : DateOffset (years = 1 ),
204
+ 'MonthBegin' : MonthBegin (1 ),
205
+ 'MonthEnd' : MonthEnd (1 ),
206
+ 'QuarterBegin' : QuarterBegin (1 ),
207
+ 'QuarterEnd' : QuarterEnd (1 ),
208
+ 'Day' : Day (1 ),
209
+ 'YearBegin' : YearBegin (1 ),
210
+ 'YearEnd' : YearEnd (1 ),
211
+ 'Week' : Week (1 ),
212
+ 'Hour' : Hour (1 ),
213
+ 'Minute' : Minute (1 )}
158
214
159
215
return dict (series = series ,
160
216
frame = frame ,
@@ -166,7 +222,8 @@ def create_data():
166
222
ts = _create_sp_tsseries ()),
167
223
sp_frame = dict (float = _create_sp_frame ()),
168
224
cat = cat ,
169
- timestamp = timestamp )
225
+ timestamp = timestamp ,
226
+ offsets = off )
170
227
171
228
172
229
def create_pickle_data ():
0 commit comments