Skip to content
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

CLN: Use is_period_dtype instead of ABCPeriodIndex checks #22958

Merged
merged 3 commits into from
Oct 3, 2018
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
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def asfreq(self, freq=None, how='E'):
if self.hasnans:
new_data[self._isnan] = iNaT

return self._simple_new(new_data, self.name, freq=freq)
return self._shallow_copy(new_data, freq=freq)

# ------------------------------------------------------------------
# Arithmetic Methods
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
is_list_like,
is_scalar,
is_bool_dtype,
is_period_dtype,
is_categorical_dtype,
is_datetime_or_timedelta_dtype,
is_float_dtype,
is_integer_dtype,
is_object_dtype,
is_string_dtype)
from pandas.core.dtypes.generic import (
ABCIndex, ABCSeries, ABCPeriodIndex, ABCIndexClass)
ABCIndex, ABCSeries, ABCIndexClass)
from pandas.core.dtypes.missing import isna
from pandas.core import common as com, algorithms, ops

Expand Down Expand Up @@ -239,9 +240,8 @@ def equals(self, other):
# have different timezone
return False

# ToDo: Remove this when PeriodDtype is added
elif isinstance(self, ABCPeriodIndex):
if not isinstance(other, ABCPeriodIndex):
elif is_period_dtype(self):
if not is_period_dtype(other):
return False
if self.freq != other.freq:
return False
Expand Down Expand Up @@ -359,7 +359,7 @@ def sort_values(self, return_indexer=False, ascending=True):
attribs = self._get_attributes_dict()
freq = attribs['freq']

if freq is not None and not isinstance(self, ABCPeriodIndex):
if freq is not None and not is_period_dtype(self):
if freq.n > 0 and not ascending:
freq = freq * -1
elif freq.n < 0 and ascending:
Expand All @@ -386,8 +386,8 @@ def take(self, indices, axis=0, allow_fill=True,
fill_value=fill_value,
na_value=iNaT)

# keep freq in PeriodIndex, reset otherwise
freq = self.freq if isinstance(self, ABCPeriodIndex) else None
# keep freq in PeriodArray/Index, reset otherwise
freq = self.freq if is_period_dtype(self) else None
return self._shallow_copy(taken, freq=freq)

_can_hold_na = True
Expand Down Expand Up @@ -618,7 +618,7 @@ def repeat(self, repeats, *args, **kwargs):
Analogous to ndarray.repeat
"""
nv.validate_repeat(args, kwargs)
if isinstance(self, ABCPeriodIndex):
if is_period_dtype(self):
freq = self.freq
else:
freq = None
Expand Down Expand Up @@ -673,7 +673,7 @@ def _concat_same_dtype(self, to_concat, name):
attribs = self._get_attributes_dict()
attribs['name'] = name

if not isinstance(self, ABCPeriodIndex):
if not is_period_dtype(self):
# reset freq
attribs['freq'] = None

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def _try_mi(k):
(compat.PY3 and isinstance(key, compat.string_types))):
try:
return _try_mi(key)
except (KeyError):
except KeyError:
raise
except (IndexError, ValueError, TypeError):
pass
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,33 +512,33 @@ def __getitem__(self, key):
# This is basically PySlice_GetIndicesEx, but delegation to our
# super routines if we don't have integers

l = len(self)
length = len(self)

# complete missing slice information
step = 1 if key.step is None else key.step
if key.start is None:
start = l - 1 if step < 0 else 0
start = length - 1 if step < 0 else 0
else:
start = key.start

if start < 0:
start += l
start += length
if start < 0:
start = -1 if step < 0 else 0
if start >= l:
start = l - 1 if step < 0 else l
if start >= length:
start = length - 1 if step < 0 else length

if key.stop is None:
stop = -1 if step < 0 else l
stop = -1 if step < 0 else length
else:
stop = key.stop

if stop < 0:
stop += l
stop += length
if stop < 0:
stop = -1
if stop > l:
stop = l
if stop > length:
stop = length

# delegate non-integer slices
if (start != int(start) or
Expand Down