Skip to content

BUG: reset identity on legacy index pickles (GH8431) #8454

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
Oct 3, 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
2 changes: 2 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ def __setstate__(self, state):
np.ndarray.__setstate__(data, state)

self._data = data
self._reset_identity()
else:
raise Exception("invalid pickle state")
_unpickle_compat = __setstate__
Expand Down Expand Up @@ -3349,6 +3350,7 @@ def __setstate__(self, state):
self._set_names(names)
self.sortorder = sortorder
self._verify_integrity()
self._reset_identity()

def __getitem__(self, key):
if np.isscalar(key):
Expand Down
Binary file added pandas/tests/data/s1-0.12.0.pkl
Binary file not shown.
Binary file added pandas/tests/data/s2-0.12.0.pkl
Binary file not shown.
11 changes: 10 additions & 1 deletion pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ def test_view(self):
i_view = i.view()
self.assertEqual(i_view.name, 'Foo')

def test_legacy_pickle_identity(self):

# GH 8431
pth = tm.get_data_path()
s1 = pd.read_pickle(os.path.join(pth,'s1-0.12.0.pkl'))
s2 = pd.read_pickle(os.path.join(pth,'s2-0.12.0.pkl'))
self.assertFalse(s1.index.identical(s2.index))
self.assertFalse(s1.index.equals(s2.index))

def test_astype(self):
casted = self.intIndex.astype('i8')

Expand Down Expand Up @@ -532,7 +541,7 @@ def test_intersection(self):
result3 = idx1.intersection(idx3)
self.assertTrue(tm.equalContents(result3, expected3))
self.assertEqual(result3.name, expected3.name)

# non-monotonic non-unique
idx1 = Index(['A','B','A','C'])
idx2 = Index(['B','D'])
Expand Down
1 change: 1 addition & 0 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ def __setstate__(self, state):
np.ndarray.__setstate__(data, state)

self._data = data
self._reset_identity()

else:
raise Exception("invalid pickle state")
Expand Down