Skip to content

Commit fccd7fe

Browse files
committed
Merge pull request pandas-dev#8454 from jreback/legacy_pickle
BUG: reset identity on legacy index pickles (GH8431)
2 parents 29b1aa7 + 6479766 commit fccd7fe

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

pandas/core/index.py

+2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ def __setstate__(self, state):
843843
np.ndarray.__setstate__(data, state)
844844

845845
self._data = data
846+
self._reset_identity()
846847
else:
847848
raise Exception("invalid pickle state")
848849
_unpickle_compat = __setstate__
@@ -3349,6 +3350,7 @@ def __setstate__(self, state):
33493350
self._set_names(names)
33503351
self.sortorder = sortorder
33513352
self._verify_integrity()
3353+
self._reset_identity()
33523354

33533355
def __getitem__(self, key):
33543356
if np.isscalar(key):

pandas/tests/data/s1-0.12.0.pkl

862 Bytes
Binary file not shown.

pandas/tests/data/s2-0.12.0.pkl

814 Bytes
Binary file not shown.

pandas/tests/test_index.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ def test_view(self):
270270
i_view = i.view()
271271
self.assertEqual(i_view.name, 'Foo')
272272

273+
def test_legacy_pickle_identity(self):
274+
275+
# GH 8431
276+
pth = tm.get_data_path()
277+
s1 = pd.read_pickle(os.path.join(pth,'s1-0.12.0.pkl'))
278+
s2 = pd.read_pickle(os.path.join(pth,'s2-0.12.0.pkl'))
279+
self.assertFalse(s1.index.identical(s2.index))
280+
self.assertFalse(s1.index.equals(s2.index))
281+
273282
def test_astype(self):
274283
casted = self.intIndex.astype('i8')
275284

@@ -532,7 +541,7 @@ def test_intersection(self):
532541
result3 = idx1.intersection(idx3)
533542
self.assertTrue(tm.equalContents(result3, expected3))
534543
self.assertEqual(result3.name, expected3.name)
535-
544+
536545
# non-monotonic non-unique
537546
idx1 = Index(['A','B','A','C'])
538547
idx2 = Index(['B','D'])

pandas/tseries/index.py

+1
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ def __setstate__(self, state):
630630
np.ndarray.__setstate__(data, state)
631631

632632
self._data = data
633+
self._reset_identity()
633634

634635
else:
635636
raise Exception("invalid pickle state")

0 commit comments

Comments
 (0)