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 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
4 changes: 1 addition & 3 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,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 @@ -164,12 +164,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
16 changes: 4 additions & 12 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,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 All @@ -407,9 +401,7 @@ def _union(self, other, sort):
else:
result = Index._union(this, other, sort=sort)
if isinstance(result, DatetimeIndex):
# TODO: we shouldn't be setting attributes like this;
# in all the tests this equality already holds
result._data._dtype = this.dtype
assert result._data.dtype == this.dtype
if result.freq is None and (
this.freq is not None or other.freq is not None
):
Expand Down
18 changes: 8 additions & 10 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,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 @@ -309,7 +307,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 @@ -321,10 +319,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