Skip to content

CLN: assorted cleanups in indexes/ #31674

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 2 commits into from
Feb 5, 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
5 changes: 5 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,11 @@ def __contains__(self, key: Any) -> bool:
bool
Whether the key search is in the index.

Raises
------
TypeError
If the key is not hashable.

See Also
--------
Index.isin : Returns an ndarray of boolean dtype indicating whether the
Expand Down
18 changes: 1 addition & 17 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate):

_typ = "categoricalindex"

_raw_inherit = {
"argsort",
"_internal_get_values",
"tolist",
"codes",
"categories",
"ordered",
"_reverse_indexer",
"searchsorted",
}

codes: np.ndarray
categories: Index
_data: Categorical
Expand Down Expand Up @@ -847,18 +836,13 @@ def _concat_same_dtype(self, to_concat, name):
result.name = name
return result

def _delegate_property_get(self, name: str, *args, **kwargs):
""" method delegation to the ._values """
prop = getattr(self._values, name)
return prop # no wrapping for now

def _delegate_method(self, name: str, *args, **kwargs):
""" method delegation to the ._values """
method = getattr(self._values, name)
if "inplace" in kwargs:
raise ValueError("cannot use inplace with CategoricalIndex")
res = method(*args, **kwargs)
if is_scalar(res) or name in self._raw_inherit:
if is_scalar(res):
return res
return CategoricalIndex(res, name=self.name)

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def sort_values(self, return_indexer=False, ascending=True):
arr = type(self._data)._simple_new(
sorted_values, dtype=self.dtype, freq=freq
)
return self._simple_new(arr, name=self.name)
return type(self)._simple_new(arr, name=self.name)

@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
Expand Down Expand Up @@ -526,7 +526,7 @@ def _concat_same_dtype(self, to_concat, name):
if is_diff_evenly_spaced:
new_data._freq = self.freq

return self._simple_new(new_data, name=name)
return type(self)._simple_new(new_data, name=name)

def shift(self, periods=1, freq=None):
"""
Expand Down Expand Up @@ -629,7 +629,7 @@ def _shallow_copy(self, values=None, **kwargs):
del attributes["freq"]

attributes.update(kwargs)
return self._simple_new(values, **attributes)
return type(self)._simple_new(values, **attributes)

# --------------------------------------------------------------------
# Set Operation Methods
Expand Down Expand Up @@ -886,7 +886,7 @@ def _wrap_joined_index(self, joined, other):
kwargs = {}
if hasattr(self, "tz"):
kwargs["tz"] = getattr(other, "tz", None)
return self._simple_new(joined, name, **kwargs)
return type(self)._simple_new(joined, name, **kwargs)

# --------------------------------------------------------------------
# List-Like Methods
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def _partial_date_slice(
raise KeyError

# a monotonic (sorted) series can be sliced
# Use asi8.searchsorted to avoid re-validating
left = stamps.searchsorted(t1.value, side="left") if use_lhs else None
right = stamps.searchsorted(t2.value, side="right") if use_rhs else None

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from pandas._libs import index as libindex
from pandas._libs.tslibs import NaT, frequencies as libfrequencies, resolution
from pandas._libs.tslibs import frequencies as libfrequencies, resolution
from pandas._libs.tslibs.parsing import parse_time_string
from pandas._libs.tslibs.period import Period
from pandas.util._decorators import Appender, cache_readonly
Expand Down Expand Up @@ -547,7 +547,7 @@ def get_loc(self, key, method=None, tolerance=None):
# we cannot construct the Period
raise KeyError(key)

ordinal = key.ordinal if key is not NaT else key.value
ordinal = self._data._unbox_scalar(key)
try:
return self._engine.get_loc(ordinal)
except KeyError:
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ def _maybe_cast_slice_bound(self, label, side: str, kind):

return label

def _get_string_slice(self, key: str, use_lhs: bool = True, use_rhs: bool = True):
# TODO: Check for non-True use_lhs/use_rhs
assert isinstance(key, str), type(key)
# given a key, try to figure out a location for a partial slice
raise NotImplementedError

def is_type_compatible(self, typ) -> bool:
return typ == self.inferred_type or typ == "timedelta"

Expand Down