Skip to content

Commit

Permalink
fix redundant isinstance checks (pandas-dev#17942)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and peterpanmj committed Oct 31, 2017
1 parent 7323783 commit 60597a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from pandas.core.common import AbstractMethodError

import pandas.io.formats.printing as printing
from pandas._libs import (tslib as libts, lib,
Timedelta, Timestamp, iNaT, NaT)
from pandas._libs import (tslib as libts, lib, iNaT, NaT)
from pandas._libs.period import Period

from pandas.core.indexes.base import Index, _index_shared_docs
Expand Down Expand Up @@ -649,13 +648,11 @@ def __add__(self, other):
return other._add_delta(self)
raise TypeError("cannot add TimedeltaIndex and {typ}"
.format(typ=type(other)))
elif isinstance(other, (DateOffset, timedelta, np.timedelta64,
Timedelta)):
elif isinstance(other, (DateOffset, timedelta, np.timedelta64)):
return self._add_delta(other)
elif is_integer(other):
return self.shift(other)
elif isinstance(other, (Index, Timestamp, datetime,
np.datetime64)):
elif isinstance(other, (Index, datetime, np.datetime64)):
return self._add_datelike(other)
else: # pragma: no cover
return NotImplemented
Expand All @@ -680,12 +677,11 @@ def __sub__(self, other):
raise TypeError("cannot subtract {typ1} and {typ2}"
.format(typ1=type(self).__name__,
typ2=type(other).__name__))
elif isinstance(other, (DateOffset, timedelta, np.timedelta64,
Timedelta)):
elif isinstance(other, (DateOffset, timedelta, np.timedelta64)):
return self._add_delta(-other)
elif is_integer(other):
return self.shift(-other)
elif isinstance(other, (Timestamp, datetime)):
elif isinstance(other, datetime):
return self._sub_datelike(other)
elif isinstance(other, Period):
return self._sub_period(other)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def _sub_datelike(self, other):
raise TypeError("DatetimeIndex subtraction must have the same "
"timezones or no timezones")
result = self._sub_datelike_dti(other)
elif isinstance(other, (libts.Timestamp, datetime)):
elif isinstance(other, datetime):
other = Timestamp(other)
if other is libts.NaT:
result = self._nat_new(box=False)
Expand Down

0 comments on commit 60597a6

Please sign in to comment.