Skip to content

Commit 05c6646

Browse files
committed
Merge pull request #7789 from sinhrks/normalize_pickle
BUG/COMPAT: pickled dtindex with freq raises AttributeError in normalize...
2 parents 16bf072 + 27c187d commit 05c6646

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

doc/source/v0.15.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Bug Fixes
189189
- Bug in ``DataFrame.as_matrix()`` with mixed ``datetime64[ns]`` and ``timedelta64[ns]`` dtypes (:issue:`7778`)
190190

191191

192+
- Bug in pickles contains ``DateOffset`` may raise ``AttributeError`` when ``normalize`` attribute is reffered internally (:issue:`7748`)
192193

193194

194195

pandas/io/tests/test_pickle.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ def compare(self, vf):
4848
# py3 compat when reading py2 pickle
4949
try:
5050
data = pandas.read_pickle(vf)
51-
except (ValueError) as detail:
52-
# trying to read a py3 pickle in py2
53-
return
51+
except (ValueError) as e:
52+
if 'unsupported pickle protocol:' in str(e):
53+
# trying to read a py3 pickle in py2
54+
return
55+
else:
56+
raise
5457

5558
for typ, dv in data.items():
5659
for dt, result in dv.items():
@@ -60,6 +63,7 @@ def compare(self, vf):
6063
continue
6164

6265
self.compare_element(typ, result, expected)
66+
return data
6367

6468
def read_pickles(self, version):
6569
if not is_little_endian():
@@ -68,7 +72,14 @@ def read_pickles(self, version):
6872
pth = tm.get_data_path('legacy_pickle/{0}'.format(str(version)))
6973
for f in os.listdir(pth):
7074
vf = os.path.join(pth,f)
71-
self.compare(vf)
75+
data = self.compare(vf)
76+
77+
if data is None:
78+
continue
79+
80+
if 'series' in data:
81+
if 'ts' in data['series']:
82+
self._validate_timeseries(data['series']['ts'], self.data['series']['ts'])
7283

7384
def test_read_pickles_0_10_1(self):
7485
self.read_pickles('0.10.1')
@@ -82,6 +93,9 @@ def test_read_pickles_0_12_0(self):
8293
def test_read_pickles_0_13_0(self):
8394
self.read_pickles('0.13.0')
8495

96+
def test_read_pickles_0_14_0(self):
97+
self.read_pickles('0.14.0')
98+
8599
def test_round_trip_current(self):
86100
for typ, dv in self.data.items():
87101

@@ -94,6 +108,14 @@ def test_round_trip_current(self):
94108
result = pd.read_pickle(path)
95109
self.compare_element(typ, result, expected)
96110

111+
def _validate_timeseries(self, pickled, current):
112+
# GH 7748
113+
tm.assert_series_equal(pickled, current)
114+
self.assertEqual(pickled.index.freq, current.index.freq)
115+
self.assertEqual(pickled.index.freq.normalize, False)
116+
self.assert_numpy_array_equal(pickled > 0, current > 0)
117+
118+
97119
if __name__ == '__main__':
98120
import nose
99121
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

pandas/tseries/offsets.py

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def __add__(date):
130130
_cacheable = False
131131
_normalize_cache = True
132132

133+
# default for prior pickles
134+
normalize = False
135+
133136
def __init__(self, n=1, normalize=False, **kwds):
134137
self.n = int(n)
135138
self.normalize = normalize

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ def pxd(name):
578578
'tests/data/legacy_pickle/0.11.0/*.pickle',
579579
'tests/data/legacy_pickle/0.12.0/*.pickle',
580580
'tests/data/legacy_pickle/0.13.0/*.pickle',
581+
'tests/data/legacy_pickle/0.14.0/*.pickle',
581582
'tests/data/*.csv',
582583
'tests/data/*.dta',
583584
'tests/data/*.txt',

0 commit comments

Comments
 (0)