Skip to content

CLN: remove unused from MultiIndex #32030

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 5 commits into from
Feb 18, 2020
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
67 changes: 1 addition & 66 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
indexer_from_factorized,
lexsort_indexer,
)
from pandas.core.util.hashing import hash_tuple, hash_tuples

from pandas.io.formats.printing import (
format_object_attrs,
Expand Down Expand Up @@ -247,6 +246,7 @@ class MultiIndex(Index):
rename = Index.set_names

_tuples = None
sortorder: Optional[int]

# --------------------------------------------------------------------
# Constructors
Expand Down Expand Up @@ -1430,55 +1430,11 @@ def is_monotonic_decreasing(self) -> bool:
# monotonic decreasing if and only if reverse is monotonic increasing
return self[::-1].is_monotonic_increasing

@cache_readonly
def _have_mixed_levels(self):
""" return a boolean list indicated if we have mixed levels """
return ["mixed" in l for l in self._inferred_type_levels]

@cache_readonly
def _inferred_type_levels(self):
""" return a list of the inferred types, one for each level """
return [i.inferred_type for i in self.levels]

@cache_readonly
def _hashed_values(self):
""" return a uint64 ndarray of my hashed values """
return hash_tuples(self)

def _hashed_indexing_key(self, key):
"""
validate and return the hash for the provided key

*this is internal for use for the cython routines*

Parameters
----------
key : string or tuple

Returns
-------
np.uint64

Notes
-----
we need to stringify if we have mixed levels
"""
if not isinstance(key, tuple):
return hash_tuples(key)

if not len(key) == self.nlevels:
raise KeyError

def f(k, stringify):
if stringify and not isinstance(k, str):
k = str(k)
return k

key = tuple(
f(k, stringify) for k, stringify in zip(key, self._have_mixed_levels)
)
return hash_tuple(key)

@Appender(Index.duplicated.__doc__)
def duplicated(self, keep="first"):
shape = map(len, self.levels)
Expand Down Expand Up @@ -1858,27 +1814,6 @@ def __reduce__(self):
)
return ibase._new_Index, (type(self), d), None

def __setstate__(self, state):
"""Necessary for making this object picklable"""
if isinstance(state, dict):
levels = state.get("levels")
codes = state.get("codes")
sortorder = state.get("sortorder")
names = state.get("names")

elif isinstance(state, tuple):

nd_state, own_state = state
levels, codes, sortorder, names = own_state

self._set_levels([Index(x) for x in levels], validate=False)
self._set_codes(codes)
new_codes = self._verify_integrity()
self._set_codes(new_codes)
self._set_names(names)
self.sortorder = sortorder
self._reset_identity()

# --------------------------------------------------------------------

def __getitem__(self, key):
Expand Down
17 changes: 0 additions & 17 deletions pandas/tests/util/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,6 @@ def test_multiindex_objects():
assert mi.equals(recons)
assert Index(mi.values).equals(Index(recons.values))

# _hashed_values and hash_pandas_object(..., index=False) equivalency.
expected = hash_pandas_object(mi, index=False).values
result = mi._hashed_values

tm.assert_numpy_array_equal(result, expected)

expected = hash_pandas_object(recons, index=False).values
result = recons._hashed_values

tm.assert_numpy_array_equal(result, expected)

expected = mi._hashed_values
result = recons._hashed_values

# Values should match, but in different order.
tm.assert_numpy_array_equal(np.sort(result), np.sort(expected))


@pytest.mark.parametrize(
"obj",
Expand Down