Skip to content

Commit 2b6148d

Browse files
jrebackalanbato
authored andcommitted
TST: add backward compat for offset testing for pickles (pandas-dev#17733)
closes pandas-dev#17721
1 parent 3f668b5 commit 2b6148d

File tree

4 files changed

+70
-21
lines changed

4 files changed

+70
-21
lines changed
Binary file not shown.
Binary file not shown.

pandas/tests/io/generate_legacy_storage_files.py

+63-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
#!/usr/env/bin python
22

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+
437
from __future__ import print_function
538
from warnings import catch_warnings
639
from distutils.version import LooseVersion
@@ -9,6 +42,11 @@
942
Index, MultiIndex, bdate_range, to_msgpack,
1043
date_range, period_range,
1144
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)
1250
from pandas.compat import u
1351
import os
1452
import sys
@@ -151,10 +189,28 @@ def create_data():
151189

152190
timestamp = dict(normal=Timestamp('2011-01-01'),
153191
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)}
158214

159215
return dict(series=series,
160216
frame=frame,
@@ -166,7 +222,8 @@ def create_data():
166222
ts=_create_sp_tsseries()),
167223
sp_frame=dict(float=_create_sp_frame()),
168224
cat=cat,
169-
timestamp=timestamp)
225+
timestamp=timestamp,
226+
offsets=off)
170227

171228

172229
def create_pickle_data():

pandas/tests/io/test_pickle.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,18 @@ def legacy_pickle_versions():
193193
for v in os.listdir(path):
194194
p = os.path.join(path, v)
195195
if os.path.isdir(p):
196-
yield v
196+
for f in os.listdir(p):
197+
yield (v, f)
197198

198199

199-
@pytest.mark.parametrize('version', legacy_pickle_versions())
200-
def test_pickles(current_pickle_data, version):
200+
@pytest.mark.parametrize('version, f', legacy_pickle_versions())
201+
def test_pickles(current_pickle_data, version, f):
201202
if not is_platform_little_endian():
202203
pytest.skip("known failure on non-little endian")
203204

204-
pth = tm.get_data_path('legacy_pickle/{0}'.format(version))
205-
n = 0
206-
for f in os.listdir(pth):
207-
vf = os.path.join(pth, f)
208-
with catch_warnings(record=True):
209-
data = compare(current_pickle_data, vf, version)
210-
211-
if data is None:
212-
continue
213-
n += 1
214-
assert n > 0, ('Pickle files are not '
215-
'tested: {version}'.format(version=version))
205+
vf = tm.get_data_path('legacy_pickle/{}/{}'.format(version, f))
206+
with catch_warnings(record=True):
207+
compare(current_pickle_data, vf, version)
216208

217209

218210
def test_round_trip_current(current_pickle_data):

0 commit comments

Comments
 (0)