8000 CLN: unreachable code in indexes by jbrockmendel · Pull Request #30694 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CLN: unreachable code in indexes #30694

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
Jan 4, 2020
Merged
Show file tree
Hide file tree
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
commit so i can rebase
  • Loading branch information
jbrockmendel committed Jan 4, 2020
commit bf2ef650fb672221b5295b77c0f934a33642649d
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4660,7 +4660,7 @@ def isin(self, values, level=None):
self._validate_index_level(level)
return algos.isin(self, values)

def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
def _get_string_slice(self, key: str, use_lhs=True, use_rhs=True):
# this is for partial string indexing,
# overridden in DatetimeIndex, TimedeltaIndex and PeriodIndex
raise NotImplementedError
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,12 @@ def _create_categorical(cls, data, dtype=None):
return data

@classmethod
def _simple_new(cls, values, name=None, dtype=None, **kwargs):
def _simple_new(cls, values, name=None, dtype=None):
result = object.__new__(cls)

values = cls._create_categorical(values, dtype=dtype)
result._data = values
result.name = name
for k, v in kwargs.items():
setattr(result, k, v)

result._reset_identity()
result._no_setting_name = False
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ def equals(self, other):
# have different timezone
return False

elif is_period_dtype(self):
if not is_period_dtype(other):
return False
if self.freq != other.freq:
return False

return np.array_equal(self.asi8, other.asi8)

def _ensure_localized(
Expand Down
12 changes: 3 additions & 9 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,12 @@ def _formatter_func(self):
# --------------------------------------------------------------------
# Set Operation Methods

def _union(self, other, sort):
def _union(self, other: "DatetimeIndex", sort):
if not len(other) or self.equals(other) or not len(self):
return super()._union(other, sort=sort)

if len(other) == 0 or self.equals(other) or len(self) == 0:
return super().union(other, sort=sort)

if not isinstance(other, DatetimeIndex):
try:
other = DatetimeIndex(other)
except TypeError:
pass
# We are called by `union`, which is responsible for this validation
assert isinstance(other, DatetimeIndex)

this, other = self._maybe_utc_convert(other)

Expand Down
26 changes: 14 additions & 12 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,13 @@ def astype(self, dtype, copy=True):
return Index(result.astype("i8"), name=self.name)
return DatetimeIndexOpsMixin.astype(self, dtype, copy=copy)

def _union(self, other, sort):
def _union(self, other: "TimedeltaIndex", sort):
if len(other) == 0 or self.equals(other) or len(self) == 0:
return super()._union(other, sort=sort)

if not isinstance(other, TimedeltaIndex):
try:
other = TimedeltaIndex(other)
except (TypeError, ValueError):
pass
# We are called by `union`, which is responsible for this validation
assert isinstance(other, TimedeltaIndex)

this, other = self, other

if this._can_fast_union(other):
Expand Down Expand Up @@ -310,7 +308,7 @@ def get_value(self, series, key):
return self.get_value_maybe_box(series, key)

try:
return com.maybe_box(self, Index.get_value(self, series, key), series, key)
value = Index.get_value(self, series, key)
except KeyError:
try:
loc = self._get_string_slice(key)
Expand All @@ -322,10 +320,10 @@ def get_value(self, series, key):
return self.get_value_maybe_box(series, key)
except (TypeError, ValueError, KeyError):
raise KeyError(key)
else:
return com.maybe_box(self, value, series, key)

def get_value_maybe_box(self, series, key):
if not isinstance(key, Timedelta):
key = Timedelta(key)
def get_value_maybe_box(self, series, key: Timedelta):
values = self._engine.get_value(com.values_from_object(series), key)
return com.maybe_box(self, values, series, key)

Expand Down Expand Up @@ -356,6 +354,7 @@ def get_loc(self, key, method=None, tolerance=None):
key = Timedelta(key)
return Index.get_loc(self, key, method, tolerance)

return Index.get_loc(self, key, method, tolerance)
try:
return Index.get_loc(self, key, method, tolerance)
except (KeyError, ValueError, TypeError):
Expand All @@ -366,7 +365,9 @@ def get_loc(self, key, method=None, tolerance=None):

try:
stamp = Timedelta(key)
return Index.get_loc(self, stamp, method, tolerance)
result = Index.get_loc(self, stamp, method, tolerance)
assert False, (key, stamp, result)
return result
except (KeyError, ValueError):
raise KeyError(key)

Expand Down Expand Up @@ -398,7 +399,8 @@ def _maybe_cast_slice_bound(self, label, side, kind):

return label

def _get_string_slice(self, key):
def _get_string_slice(self, key: str):
# FIXME: we should never get integer or float or NaT here
if is_integer(key) or is_float(key) or key is NaT:
self._invalid_indexer("slice", key)
loc = self._partial_td_slice(key)
Expand Down
0