Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: add backward compat for offset testing for pickles #17733

Merged
merged 1 commit into from
Oct 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
69 changes: 63 additions & 6 deletions pandas/tests/io/generate_legacy_storage_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
#!/usr/env/bin python

""" self-contained to write legacy storage (pickle/msgpack) files """
"""
self-contained to write legacy storage (pickle/msgpack) files

To use this script. Create an environment where you want
generate pickles, say its for 0.18.1, with your pandas clone
in ~/pandas

. activate pandas_0.18.1
cd ~/

$ python pandas/pandas/tests/io/generate_legacy_storage_files.py \
pandas/pandas/tests/io/data/legacy_pickle/0.18.1/ pickle

This script generates a storage file for the current arch, system,
and python version
pandas version: 0.18.1
output dir : pandas/pandas/tests/io/data/legacy_pickle/0.18.1/
storage format: pickle
created pickle file: 0.18.1_x86_64_darwin_3.5.2.pickle

The idea here is you are using the *current* version of the
generate_legacy_storage_files with an *older* version of pandas to
generate a pickle file. We will then check this file into a current
branch, and test using test_pickle.py. This will load the *older*
pickles and test versus the current data that is generated
(with master). These are then compared.

If we have cases where we changed the signature (e.g. we renamed
offset -> freq in Timestamp). Then we have to conditionally execute
in the generate_legacy_storage_files.py to make it
run under the older AND the newer version.

"""

from __future__ import print_function
from warnings import catch_warnings
from distutils.version import LooseVersion
Expand All @@ -9,6 +42,11 @@
Index, MultiIndex, bdate_range, to_msgpack,
date_range, period_range,
Timestamp, NaT, Categorical, Period)
from pandas.tseries.offsets import (
DateOffset, Hour, Minute, Day,
MonthBegin, MonthEnd, YearBegin,
YearEnd, Week,
QuarterBegin, QuarterEnd)
from pandas.compat import u
import os
import sys
Expand Down Expand Up @@ -151,10 +189,28 @@ def create_data():

timestamp = dict(normal=Timestamp('2011-01-01'),
nat=NaT,
tz=Timestamp('2011-01-01', tz='US/Eastern'),
freq=Timestamp('2011-01-01', freq='D'),
both=Timestamp('2011-01-01', tz='Asia/Tokyo',
freq='M'))
tz=Timestamp('2011-01-01', tz='US/Eastern'))

if _loose_version < '0.19.2':
timestamp['freq'] = Timestamp('2011-01-01', offset='D')
timestamp['both'] = Timestamp('2011-01-01', tz='Asia/Tokyo',
offset='M')
else:
timestamp['freq'] = Timestamp('2011-01-01', freq='D')
timestamp['both'] = Timestamp('2011-01-01', tz='Asia/Tokyo',
freq='M')

off = {'DateOffset': DateOffset(years=1),
'MonthBegin': MonthBegin(1),
'MonthEnd': MonthEnd(1),
'QuarterBegin': QuarterBegin(1),
'QuarterEnd': QuarterEnd(1),
'Day': Day(1),
'YearBegin': YearBegin(1),
'YearEnd': YearEnd(1),
'Week': Week(1),
'Hour': Hour(1),
'Minute': Minute(1)}

return dict(series=series,
frame=frame,
Expand All @@ -166,7 +222,8 @@ def create_data():
ts=_create_sp_tsseries()),
sp_frame=dict(float=_create_sp_frame()),
cat=cat,
timestamp=timestamp)
timestamp=timestamp,
offsets=off)


def create_pickle_data():
Expand Down
22 changes: 7 additions & 15 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,18 @@ def legacy_pickle_versions():
for v in os.listdir(path):
p = os.path.join(path, v)
if os.path.isdir(p):
yield v
for f in os.listdir(p):
yield (v, f)


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

pth = tm.get_data_path('legacy_pickle/{0}'.format(version))
n = 0
for f in os.listdir(pth):
vf = os.path.join(pth, f)
with catch_warnings(record=True):
data = compare(current_pickle_data, vf, version)

if data is None:
continue
n += 1
assert n > 0, ('Pickle files are not '
'tested: {version}'.format(version=version))
vf = tm.get_data_path('legacy_pickle/{}/{}'.format(version, f))
with catch_warnings(record=True):
compare(current_pickle_data, vf, version)


def test_round_trip_current(current_pickle_data):
Expand Down