From e1dabf37645f0fcabeed1d845a0ada7b32415606 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 23 Oct 2017 03:22:24 -0700 Subject: [PATCH] fix redundant isinstance checks (#17942) --- pandas/core/indexes/datetimelike.py | 14 +++++--------- pandas/core/indexes/datetimes.py | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 5d40975586e73..71de6c7c3e8cf 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -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 @@ -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 @@ -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) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index d16251a7829b9..18be6c61abdf7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -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)