From 64083b3d5755713b0f7589110aa459c192f5aeae Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 15 Feb 2020 11:38:31 -0800 Subject: [PATCH 1/3] CLN: remove unused from MultiIndex --- pandas/core/indexes/multi.py | 62 +----------------------------------- 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 02e11c0e71cbe..a1b19e64b53de 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -58,7 +58,7 @@ indexer_from_factorized, lexsort_indexer, ) -from pandas.core.util.hashing import hash_tuple, hash_tuples +from pandas.core.util.hashing import hash_tuples from pandas.io.formats.printing import ( format_object_attrs, @@ -1430,11 +1430,6 @@ 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 """ @@ -1445,40 +1440,6 @@ 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) @@ -1858,27 +1819,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): From dfc401b0250f2b9d0084469879ad6bda277552cf Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 15 Feb 2020 11:47:35 -0800 Subject: [PATCH 2/3] remove _hashed_values --- pandas/core/indexes/multi.py | 6 ------ pandas/tests/util/test_hashing.py | 17 ----------------- 2 files changed, 23 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index a1b19e64b53de..cfc4adef59f9f 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -58,7 +58,6 @@ indexer_from_factorized, lexsort_indexer, ) -from pandas.core.util.hashing import hash_tuples from pandas.io.formats.printing import ( format_object_attrs, @@ -1435,11 +1434,6 @@ 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) - @Appender(Index.duplicated.__doc__) def duplicated(self, keep="first"): shape = map(len, self.levels) diff --git a/pandas/tests/util/test_hashing.py b/pandas/tests/util/test_hashing.py index c856585f20138..6411b9ab654f1 100644 --- a/pandas/tests/util/test_hashing.py +++ b/pandas/tests/util/test_hashing.py @@ -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", From 6c74afe0230497512a015139b9ae2d551ce11ada Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 16 Feb 2020 15:33:48 -0800 Subject: [PATCH 3/3] add sortorder --- pandas/core/indexes/multi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index cfc4adef59f9f..0a79df0cc9744 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -246,6 +246,7 @@ class MultiIndex(Index): rename = Index.set_names _tuples = None + sortorder: Optional[int] # -------------------------------------------------------------------- # Constructors