diff --git a/pandas/core/index.py b/pandas/core/index.py index b528a628234cc..da8edf13ff18f 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -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__ @@ -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): diff --git a/pandas/tests/data/s1-0.12.0.pkl b/pandas/tests/data/s1-0.12.0.pkl new file mode 100644 index 0000000000000..0ce9cfdf3aa94 Binary files /dev/null and b/pandas/tests/data/s1-0.12.0.pkl differ diff --git a/pandas/tests/data/s2-0.12.0.pkl b/pandas/tests/data/s2-0.12.0.pkl new file mode 100644 index 0000000000000..2318be2d9978b Binary files /dev/null and b/pandas/tests/data/s2-0.12.0.pkl differ diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 3001c4f09d982..5f240e896f57c 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -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') @@ -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']) diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py index 2483e0ebb32a5..7aaec511b82bf 100644 --- a/pandas/tseries/index.py +++ b/pandas/tseries/index.py @@ -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")