Skip to content

CLN: Remove Legacy MultiIndex Index Compatibility #21740

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
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: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ Missing
MultiIndex
^^^^^^^^^^

-
- Removed compatibility for MultiIndex pickles prior to version 0.8.0; compatibility with MultiIndex pickles from version 0.13 forward is maintained (:issue:`21654`)
-
-

Expand Down
25 changes: 0 additions & 25 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,15 +824,6 @@ def values(self):
self._tuples = lib.fast_zip(values)
return self._tuples

# fml
@property
def _is_v1(self):
return False

@property
def _is_v2(self):
return False

@property
def _has_complex_internals(self):
# to disable groupby tricks
Expand Down Expand Up @@ -2843,22 +2834,6 @@ def delete(self, loc):
return MultiIndex(levels=self.levels, labels=new_labels,
names=self.names, verify_integrity=False)

get_major_bounds = slice_locs

__bounds = None

@property
def _bounds(self):
"""
Return or compute and return slice points for level 0, assuming
sortedness
"""
if self.__bounds is None:
inds = np.arange(len(self.levels[0]))
self.__bounds = self.labels[0].searchsorted(inds)

return self.__bounds

def _wrap_joined_index(self, joined, other):
names = self.names if self.names == other.names else None
return MultiIndex.from_tuples(joined, names=names)
Expand Down
Binary file removed pandas/tests/indexes/multi/data/mindex_073.pickle
Binary file not shown.
149 changes: 0 additions & 149 deletions pandas/tests/indexes/multi/data/multiindex_v1.pickle

This file was deleted.

4 changes: 0 additions & 4 deletions pandas/tests/indexes/multi/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def test_shift(idx):
pytest.raises(NotImplementedError, idx.shift, 1, 2)


def test_bounds(idx):
idx._bounds


def test_groupby(idx):
groups = idx.groupby(np.array([1, 1, 1, 2, 2, 2]))
labels = idx.get_values().tolist()
Expand Down
45 changes: 2 additions & 43 deletions pandas/tests/indexes/multi/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import numpy as np
import pandas as pd
import pandas.util.testing as tm
import pytest
from pandas import DataFrame, MultiIndex, date_range
from pandas.compat import PY3, range
from pandas.util.testing import assert_almost_equal
from pandas.compat import range


def test_tolist(idx):
Expand Down Expand Up @@ -93,46 +91,6 @@ def test_to_hierarchical():
assert result.names == index.names


@pytest.mark.skipif(PY3, reason="testing legacy pickles not support on py3")
def test_legacy_pickle(datapath):

path = datapath('indexes', 'multi', 'data', 'multiindex_v1.pickle')
obj = pd.read_pickle(path)
Copy link
Contributor

Choose a reason for hiding this comment

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

can u also remove the legacy code itself from MultiIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I came to the conclusion that I can just delete the __setstate__ method as there is no associated __getstate__ method. I hope this approach is correct.


obj2 = MultiIndex.from_tuples(obj.values)
assert obj.equals(obj2)

res = obj.get_indexer(obj)
exp = np.arange(len(obj), dtype=np.intp)
assert_almost_equal(res, exp)

res = obj.get_indexer(obj2[::-1])
exp = obj.get_indexer(obj[::-1])
exp2 = obj2.get_indexer(obj2[::-1])
assert_almost_equal(res, exp)
assert_almost_equal(exp, exp2)


def test_legacy_v2_unpickle(datapath):

# 0.7.3 -> 0.8.0 format manage
path = datapath('indexes', 'multi', 'data', 'mindex_073.pickle')
obj = pd.read_pickle(path)

obj2 = MultiIndex.from_tuples(obj.values)
assert obj.equals(obj2)

res = obj.get_indexer(obj)
exp = np.arange(len(obj), dtype=np.intp)
assert_almost_equal(res, exp)

res = obj.get_indexer(obj2[::-1])
exp = obj.get_indexer(obj[::-1])
exp2 = obj2.get_indexer(obj2[::-1])
assert_almost_equal(res, exp)
assert_almost_equal(exp, exp2)


def test_roundtrip_pickle_with_tz():

# GH 8367
Expand All @@ -146,6 +104,7 @@ def test_roundtrip_pickle_with_tz():


def test_pickle(indices):

unpickled = tm.round_trip_pickle(indices)
assert indices.equals(unpickled)
original_name, indices.name = indices.name, 'foo'
Expand Down