Skip to content

CLN: prelims for MultiIndex.get_value #31640

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

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 19 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from sys import getsizeof
from typing import Any, Hashable, Iterable, List, Optional, Sequence, Tuple, Union
from typing import (
TYPE_CHECKING,
Any,
Hashable,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
)
import warnings

import numpy as np
Expand Down Expand Up @@ -27,7 +37,7 @@
pandas_dtype,
)
from pandas.core.dtypes.dtypes import ExtensionDtype
from pandas.core.dtypes.generic import ABCDataFrame
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
from pandas.core.dtypes.missing import array_equivalent, isna

import pandas.core.algorithms as algos
Expand Down Expand Up @@ -56,6 +66,9 @@
pprint_thing,
)

if TYPE_CHECKING:
from pandas import Series # noqa:F401

_index_doc_kwargs = dict(ibase._index_doc_kwargs)
_index_doc_kwargs.update(
dict(klass="MultiIndex", target_klass="MultiIndex or list of tuples")
Expand Down Expand Up @@ -2318,8 +2331,10 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
# --------------------------------------------------------------------
# Indexing Methods

def get_value(self, series, key):
def get_value(self, series: "Series", key):
# Label-based
assert isinstance(series, ABCSeries)

if not is_hashable(key) or is_iterator(key):
# We allow tuples if they are hashable, whereas other Index
# subclasses require scalar.
Expand All @@ -2338,7 +2353,7 @@ def _try_mi(k):
new_index = maybe_droplevels(new_index, k)
return series._constructor(
new_values, index=new_index, name=series.name
).__finalize__(self)
).__finalize__(series)

try:
return _try_mi(key)
Expand Down