Skip to content

CLN: avoid _ndarray_values, values in MultiIndex #32452

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 4 commits into from
Mar 8, 2020
Merged
Changes from 1 commit
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
Next Next commit
Avoid _ndarray_values in MultiIndex
  • Loading branch information
jbrockmendel committed Mar 4, 2020
commit cd6787dd36525e54149c728fd03b37f974bf25d8
22 changes: 13 additions & 9 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from pandas._libs import algos as libalgos, index as libindex, lib
from pandas._libs.hashtable import duplicated_int64
from pandas._typing import AnyArrayLike, ArrayLike, Scalar
from pandas._typing import AnyArrayLike, Scalar
from pandas.compat.numpy import function as nv
from pandas.errors import PerformanceWarning, UnsortedIndexError
from pandas.util._decorators import Appender, cache_readonly
Expand Down Expand Up @@ -52,6 +52,7 @@
ensure_index,
)
from pandas.core.indexes.frozen import FrozenList
from pandas.core.indexes.numeric import Int64Index
import pandas.core.missing as missing
from pandas.core.sorting import (
get_group_index,
Expand Down Expand Up @@ -2949,7 +2950,7 @@ def get_locs(self, seq):
n = len(self)
indexer = None

def _convert_to_indexer(r):
def _convert_to_indexer(r) -> Int64Index:
# return an indexer
if isinstance(r, slice):
m = np.zeros(n, dtype=bool)
Expand Down Expand Up @@ -3026,13 +3027,16 @@ def _update_indexer(idxr, indexer=indexer):
if indexer is None:
return np.array([], dtype=np.int64)

assert isinstance(indexer, Int64Index), type(indexer)
indexer = self._reorder_indexer(seq, indexer)

return indexer._ndarray_values
return indexer._values

def _reorder_indexer(
self, seq: Tuple[Union[Scalar, Iterable, AnyArrayLike], ...], indexer: ArrayLike
) -> ArrayLike:
self,
seq: Tuple[Union[Scalar, Iterable, AnyArrayLike], ...],
indexer: Int64Index,
) -> Int64Index:
"""
Reorder an indexer of a MultiIndex (self) so that the label are in the
same order as given in seq
Expand Down Expand Up @@ -3139,8 +3143,8 @@ def equals(self, other) -> bool:
if self.nlevels != other.nlevels:
return False

other_vals = com.values_from_object(ensure_index(other))
return array_equivalent(self._ndarray_values, other_vals)
other_vals = com.values_from_object(other)
return array_equivalent(self._values, other_vals)

if self.nlevels != other.nlevels:
return False
Expand Down Expand Up @@ -3232,7 +3236,7 @@ def union(self, other, sort=None):
# TODO: Index.union returns other when `len(self)` is 0.

uniq_tuples = lib.fast_unique_multiple(
[self._ndarray_values, other._ndarray_values], sort=sort
[self._values, other._ndarray_values], sort=sort
)

return MultiIndex.from_arrays(
Expand Down Expand Up @@ -3267,7 +3271,7 @@ def intersection(self, other, sort=False):
if self.equals(other):
return self

lvals = self._ndarray_values
lvals = self._values
rvals = other._ndarray_values

uniq_tuples = None # flag whether _inner_indexer was succesful
Expand Down