Skip to content

BUG/COMPAT: pickled dtindex with freq raises AttributeError in normalize... #7789

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

Merged
merged 1 commit into from
Jul 19, 2014
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
1 change: 1 addition & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Bug Fixes
- Bug in ``DataFrame.as_matrix()`` with mixed ``datetime64[ns]`` and ``timedelta64[ns]`` dtypes (:issue:`7778`)


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



Expand Down
30 changes: 26 additions & 4 deletions pandas/io/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ def compare(self, vf):
# py3 compat when reading py2 pickle
try:
data = pandas.read_pickle(vf)
except (ValueError) as detail:
# trying to read a py3 pickle in py2
return
except (ValueError) as e:
if 'unsupported pickle protocol:' in str(e):
# trying to read a py3 pickle in py2
return
else:
raise

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

self.compare_element(typ, result, expected)
return data

def read_pickles(self, version):
if not is_little_endian():
Expand All @@ -68,7 +72,14 @@ def read_pickles(self, version):
pth = tm.get_data_path('legacy_pickle/{0}'.format(str(version)))
for f in os.listdir(pth):
vf = os.path.join(pth,f)
self.compare(vf)
data = self.compare(vf)

if data is None:
continue

if 'series' in data:
if 'ts' in data['series']:
self._validate_timeseries(data['series']['ts'], self.data['series']['ts'])

def test_read_pickles_0_10_1(self):
self.read_pickles('0.10.1')
Expand All @@ -82,6 +93,9 @@ def test_read_pickles_0_12_0(self):
def test_read_pickles_0_13_0(self):
self.read_pickles('0.13.0')

def test_read_pickles_0_14_0(self):
self.read_pickles('0.14.0')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you add a pickle file? (I think you have to explicity add them as they are normally exluded)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File was added in #7607, but test function was missed.


def test_round_trip_current(self):
for typ, dv in self.data.items():

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

def _validate_timeseries(self, pickled, current):
# GH 7748
tm.assert_series_equal(pickled, current)
self.assertEqual(pickled.index.freq, current.index.freq)
self.assertEqual(pickled.index.freq.normalize, False)
self.assert_numpy_array_equal(pickled > 0, current > 0)


if __name__ == '__main__':
import nose
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
Expand Down
3 changes: 3 additions & 0 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def __add__(date):
_cacheable = False
_normalize_cache = True

# default for prior pickles
normalize = False

def __init__(self, n=1, normalize=False, **kwds):
self.n = int(n)
self.normalize = normalize
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ def pxd(name):
'tests/data/legacy_pickle/0.11.0/*.pickle',
'tests/data/legacy_pickle/0.12.0/*.pickle',
'tests/data/legacy_pickle/0.13.0/*.pickle',
'tests/data/legacy_pickle/0.14.0/*.pickle',
'tests/data/*.csv',
'tests/data/*.dta',
'tests/data/*.txt',
Expand Down