Skip to content

Commit e1dabf3

Browse files
jbrockmendeljreback
authored andcommitted
fix redundant isinstance checks (pandas-dev#17942)
1 parent 097eb69 commit e1dabf3

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

pandas/core/indexes/datetimelike.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
from pandas.core.common import AbstractMethodError
2525

2626
import pandas.io.formats.printing as printing
27-
from pandas._libs import (tslib as libts, lib,
28-
Timedelta, Timestamp, iNaT, NaT)
27+
from pandas._libs import (tslib as libts, lib, iNaT, NaT)
2928
from pandas._libs.period import Period
3029

3130
from pandas.core.indexes.base import Index, _index_shared_docs
@@ -649,13 +648,11 @@ def __add__(self, other):
649648
return other._add_delta(self)
650649
raise TypeError("cannot add TimedeltaIndex and {typ}"
651650
.format(typ=type(other)))
652-
elif isinstance(other, (DateOffset, timedelta, np.timedelta64,
653-
Timedelta)):
651+
elif isinstance(other, (DateOffset, timedelta, np.timedelta64)):
654652
return self._add_delta(other)
655653
elif is_integer(other):
656654
return self.shift(other)
657-
elif isinstance(other, (Index, Timestamp, datetime,
658-
np.datetime64)):
655+
elif isinstance(other, (Index, datetime, np.datetime64)):
659656
return self._add_datelike(other)
660657
else: # pragma: no cover
661658
return NotImplemented
@@ -680,12 +677,11 @@ def __sub__(self, other):
680677
raise TypeError("cannot subtract {typ1} and {typ2}"
681678
.format(typ1=type(self).__name__,
682679
typ2=type(other).__name__))
683-
elif isinstance(other, (DateOffset, timedelta, np.timedelta64,
684-
Timedelta)):
680+
elif isinstance(other, (DateOffset, timedelta, np.timedelta64)):
685681
return self._add_delta(-other)
686682
elif is_integer(other):
687683
return self.shift(-other)
688-
elif isinstance(other, (Timestamp, datetime)):
684+
elif isinstance(other, datetime):
689685
return self._sub_datelike(other)
690686
elif isinstance(other, Period):
691687
return self._sub_period(other)

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def _sub_datelike(self, other):
767767
raise TypeError("DatetimeIndex subtraction must have the same "
768768
"timezones or no timezones")
769769
result = self._sub_datelike_dti(other)
770-
elif isinstance(other, (libts.Timestamp, datetime)):
770+
elif isinstance(other, datetime):
771771
other = Timestamp(other)
772772
if other is libts.NaT:
773773
result = self._nat_new(box=False)

0 commit comments

Comments
 (0)