From 1293941f1c65df0a6419cf1509695464d59abd92 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 14 Oct 2018 17:55:58 -0700 Subject: [PATCH 1/5] Move maybe_convert_timedelta back out of PeriodArraY --- pandas/core/arrays/period.py | 45 +--------------------------------- pandas/core/indexes/period.py | 46 ++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 8624ddd8965e8..50e0a933c16ae 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -5,7 +5,6 @@ import numpy as np -from pandas._libs import lib from pandas._libs.tslib import NaT, iNaT from pandas._libs.tslibs.period import ( Period, IncompatibleFrequency, DIFFERENT_FREQ_INDEX, @@ -26,7 +25,7 @@ import pandas.core.common as com from pandas.tseries import frequencies -from pandas.tseries.offsets import Tick, DateOffset +from pandas.tseries.offsets import Tick from pandas.core.arrays import datetimelike as dtl from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin @@ -445,48 +444,6 @@ def _time_shift(self, n): values[self._isnan] = iNaT return self._shallow_copy(values=values) - def _maybe_convert_timedelta(self, other): - """ - Convert timedelta-like input to an integer multiple of self.freq - - Parameters - ---------- - other : timedelta, np.timedelta64, DateOffset, int, np.ndarray - - Returns - ------- - converted : int, np.ndarray[int64] - - Raises - ------ - IncompatibleFrequency : if the input cannot be written as a multiple - of self.freq. Note IncompatibleFrequency subclasses ValueError. - """ - if isinstance( - other, (timedelta, np.timedelta64, Tick, np.ndarray)): - offset = frequencies.to_offset(self.freq.rule_code) - if isinstance(offset, Tick): - # _check_timedeltalike_freq_compat will raise if incompatible - delta = self._check_timedeltalike_freq_compat(other) - return delta - elif isinstance(other, DateOffset): - freqstr = other.rule_code - base = frequencies.get_base_alias(freqstr) - if base == self.freq.rule_code: - return other.n - msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr) - raise IncompatibleFrequency(msg) - elif lib.is_integer(other): - # integer is passed to .shift via - # _add_datetimelike_methods basically - # but ufunc may pass integer to _add_delta - return other - - # raise when input doesn't have freq - msg = "Input has different freq from {cls}(freq={freqstr})" - raise IncompatibleFrequency(msg.format(cls=type(self).__name__, - freqstr=self.freqstr)) - def _check_timedeltalike_freq_compat(self, other): """ Arithmetic operations with timedelta-like scalars or array `other` diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index f452a57e82725..4d87cd304d991 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -1,5 +1,5 @@ # pylint: disable=E1101,E1103,W0232 -from datetime import datetime +from datetime import datetime, timedelta import numpy as np import warnings @@ -16,6 +16,8 @@ pandas_dtype, ensure_object) +from pandas.tseries.offsets import DateOffset, Tick +from pandas.tseries import frequencies from pandas.tseries.frequencies import get_freq_code as _gfc from pandas.core.indexes.datetimes import DatetimeIndex, Int64Index, Index @@ -726,6 +728,48 @@ def __setstate__(self, state): _unpickle_compat = __setstate__ + def _maybe_convert_timedelta(self, other): + """ + Convert timedelta-like input to an integer multiple of self.freq + + Parameters + ---------- + other : timedelta, np.timedelta64, DateOffset, int, np.ndarray + + Returns + ------- + converted : int, np.ndarray[int64] + + Raises + ------ + IncompatibleFrequency : if the input cannot be written as a multiple + of self.freq. Note IncompatibleFrequency subclasses ValueError. + """ + if isinstance( + other, (timedelta, np.timedelta64, Tick, np.ndarray)): + offset = frequencies.to_offset(self.freq.rule_code) + if isinstance(offset, Tick): + # _check_timedeltalike_freq_compat will raise if incompatible + delta = self._check_timedeltalike_freq_compat(other) + return delta + elif isinstance(other, DateOffset): + freqstr = other.rule_code + base = frequencies.get_base_alias(freqstr) + if base == self.freq.rule_code: + return other.n + msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr) + raise IncompatibleFrequency(msg) + elif is_integer(other): + # integer is passed to .shift via + # _add_datetimelike_methods basically + # but ufunc may pass integer to _add_delta + return other + + # raise when input doesn't have freq + msg = "Input has different freq from {cls}(freq={freqstr})" + raise IncompatibleFrequency(msg.format(cls=type(self).__name__, + freqstr=self.freqstr)) + PeriodIndex._add_comparison_ops() PeriodIndex._add_numeric_methods_disabled() From dc468a70e77f59f997e13741befb0a376a68ed33 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 15 Oct 2018 10:02:40 -0700 Subject: [PATCH 2/5] remove unreachable branches from datetimelike arithmetic ops --- pandas/core/arrays/datetimelike.py | 6 +-- pandas/core/arrays/datetimes.py | 68 ++++++++++++------------------ pandas/core/arrays/period.py | 6 +-- pandas/core/arrays/timedeltas.py | 6 --- 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index a98b0b3bf35f9..a10a26a3d99fe 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -361,7 +361,7 @@ def _add_offset(self, offset): raise com.AbstractMethodError(self) def _add_delta(self, other): - return NotImplemented + raise com.AbstractMethodError(self) def _add_delta_td(self, other): """ @@ -380,7 +380,7 @@ def _add_delta_tdi(self, other): Add a delta of a TimedeltaIndex return the i8 result view """ - if not len(self) == len(other): + if len(self) != len(other): raise ValueError("cannot add indices of unequal length") if isinstance(other, np.ndarray): @@ -441,7 +441,7 @@ def _sub_period_array(self, other): .format(dtype=other.dtype, cls=type(self).__name__)) - if not len(self) == len(other): + if len(self) != len(other): raise ValueError("cannot subtract arrays/indices of " "unequal length") if self.freq != other.freq: diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 4cc33d7afd6c8..65f17c5b48ce6 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -425,10 +425,20 @@ def _assert_tzawareness_compat(self, other): # Arithmetic Methods def _sub_datelike_dti(self, other): - """subtraction of two DatetimeIndexes""" - if not len(self) == len(other): + """subtraction of DatetimeArray/Index or ndarray[datetime64]""" + if len(self) != len(other): raise ValueError("cannot add indices of unequal length") + if not isinstance(other, DatetimeArrayMixin): + # i.e. np.ndarray; we assume it is datetime64-dtype + other = type(self)(other) + + if not self._has_same_tz(other): + # require tz compat + raise TypeError("{cls} subtraction must have the same " + "timezones or no timezones" + .format(cls=type(self).__name__)) + self_i8 = self.asi8 other_i8 = other.asi8 new_values = checked_add_with_arr(self_i8, -other_i8, @@ -459,34 +469,22 @@ def _add_offset(self, offset): def _sub_datelike(self, other): # subtract a datetime from myself, yielding a ndarray[timedelta64[ns]] if isinstance(other, (DatetimeArrayMixin, np.ndarray)): - if isinstance(other, np.ndarray): - # if other is an ndarray, we assume it is datetime64-dtype - other = type(self)(other) - if not self._has_same_tz(other): - # require tz compat - raise TypeError("{cls} subtraction must have the same " - "timezones or no timezones" - .format(cls=type(self).__name__)) - result = self._sub_datelike_dti(other) - elif isinstance(other, (datetime, np.datetime64)): - assert other is not NaT - other = Timestamp(other) - if other is NaT: - return self - NaT + return self._sub_datelike_dti(other) + + assert isinstance(other, (datetime, np.datetime64)) + assert other is not NaT + other = Timestamp(other) + if other is NaT: + return self - NaT + elif not self._has_same_tz(other): # require tz compat - elif not self._has_same_tz(other): - raise TypeError("Timestamp subtraction must have the same " - "timezones or no timezones") - else: - i8 = self.asi8 - result = checked_add_with_arr(i8, -other.value, - arr_mask=self._isnan) - result = self._maybe_mask_results(result, - fill_value=iNaT) - else: - raise TypeError("cannot subtract {cls} and {typ}" - .format(cls=type(self).__name__, - typ=type(other).__name__)) + raise TypeError("Timestamp subtraction must have the same " + "timezones or no timezones") + i8 = self.asi8 + result = checked_add_with_arr(i8, -other.value, + arr_mask=self._isnan) + result = self._maybe_mask_results(result, + fill_value=iNaT) return result.view('timedelta64[ns]') def _add_delta(self, delta): @@ -508,22 +506,12 @@ def _add_delta(self, delta): The result's name is set outside of _add_delta by the calling method (__add__ or __sub__) """ - from pandas.core.arrays.timedeltas import TimedeltaArrayMixin - if isinstance(delta, (Tick, timedelta, np.timedelta64)): new_values = self._add_delta_td(delta) elif is_timedelta64_dtype(delta): - if not isinstance(delta, TimedeltaArrayMixin): - delta = TimedeltaArrayMixin(delta) new_values = self._add_delta_tdi(delta) - else: - new_values = self.astype('O') + delta - tz = 'UTC' if self.tz is not None else None - result = type(self)(new_values, tz=tz, freq='infer') - if self.tz is not None and self.tz is not utc: - result = result.tz_convert(self.tz) - return result + return type(self)(new_values, tz=self.tz, freq='infer') # ----------------------------------------------------------------- # Timezone Conversion and Localization Methods diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 50e0a933c16ae..4af8fb92387d8 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -403,13 +403,11 @@ def _add_delta(self, other): # i8 view or _shallow_copy if isinstance(other, (Tick, timedelta, np.timedelta64)): new_values = self._add_delta_td(other) - return self._shallow_copy(new_values) elif is_timedelta64_dtype(other): # ndarray[timedelta64] or TimedeltaArray/index new_values = self._add_delta_tdi(other) - return self._shallow_copy(new_values) - else: # pragma: no cover - raise TypeError(type(other).__name__) + + return self._shallow_copy(new_values) @deprecate_kwarg(old_arg_name='n', new_arg_name='periods') def shift(self, periods): diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 4904a90ab7b2b..30553762b0c6e 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -216,15 +216,9 @@ def _add_delta(self, delta): """ if isinstance(delta, (Tick, timedelta, np.timedelta64)): new_values = self._add_delta_td(delta) - elif isinstance(delta, TimedeltaArrayMixin): - new_values = self._add_delta_tdi(delta) elif is_timedelta64_dtype(delta): # ndarray[timedelta64] --> wrap in TimedeltaArray/Index - delta = type(self)(delta) new_values = self._add_delta_tdi(delta) - else: - raise TypeError("cannot add the type {0} to a TimedeltaIndex" - .format(type(delta))) return type(self)(new_values, freq='infer') From e51a5fe79799850dd18ae4a90064dc6db25b24d5 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 15 Oct 2018 10:05:36 -0700 Subject: [PATCH 3/5] remove nat_new, only used once outside tests --- pandas/core/arrays/datetimelike.py | 25 +++------------------ pandas/tests/indexes/datetimes/test_ops.py | 10 --------- pandas/tests/indexes/period/test_ops.py | 11 --------- pandas/tests/indexes/timedeltas/test_ops.py | 11 --------- 4 files changed, 3 insertions(+), 54 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index a10a26a3d99fe..951cc0b14ef3f 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -246,27 +246,6 @@ def _maybe_mask_results(self, result, fill_value=None, convert=None): result[self._isnan] = fill_value return result - def _nat_new(self, box=True): - """ - Return Array/Index or ndarray filled with NaT which has the same - length as the caller. - - Parameters - ---------- - box : boolean, default True - - If True returns a Array/Index as the same as caller. - - If False returns ndarray of np.int64. - """ - result = np.zeros(len(self), dtype=np.int64) - result.fill(iNaT) - if not box: - return result - - attribs = self._get_attributes_dict() - if not is_period_dtype(self): - attribs['freq'] = None - return self._simple_new(result, **attribs) - # ------------------------------------------------------------------ # Frequency Properties/Methods @@ -407,7 +386,9 @@ def _add_nat(self): # GH#19124 pd.NaT is treated like a timedelta for both timedelta # and datetime dtypes - return self._nat_new(box=True) + result = np.zeros(len(self), dtype=np.int64) + result.fill(iNaT) + return self._shallow_copy(result, freq=None) def _sub_nat(self): """Subtract pd.NaT from self""" diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index b60b222d095b9..ec9c293bbe988 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -339,16 +339,6 @@ def test_infer_freq(self, freq): tm.assert_index_equal(idx, result) assert result.freq == freq - def test_nat_new(self): - idx = pd.date_range('2011-01-01', freq='D', periods=5, name='x') - result = idx._nat_new() - exp = pd.DatetimeIndex([pd.NaT] * 5, name='x') - tm.assert_index_equal(result, exp) - - result = idx._nat_new(box=False) - exp = np.array([tslib.iNaT] * 5, dtype=np.int64) - tm.assert_numpy_array_equal(result, exp) - def test_nat(self, tz_naive_fixture): tz = tz_naive_fixture assert pd.DatetimeIndex._na_value is pd.NaT diff --git a/pandas/tests/indexes/period/test_ops.py b/pandas/tests/indexes/period/test_ops.py index 85aa3f6a38fb3..25a73ffad4ecb 100644 --- a/pandas/tests/indexes/period/test_ops.py +++ b/pandas/tests/indexes/period/test_ops.py @@ -314,17 +314,6 @@ def test_order(self): tm.assert_numpy_array_equal(indexer, exp, check_dtype=False) assert ordered.freq == 'D' - def test_nat_new(self): - - idx = pd.period_range('2011-01', freq='M', periods=5, name='x') - result = idx._nat_new() - exp = pd.PeriodIndex([pd.NaT] * 5, freq='M', name='x') - tm.assert_index_equal(result, exp) - - result = idx._nat_new(box=False) - exp = np.array([tslib.iNaT] * 5, dtype=np.int64) - tm.assert_numpy_array_equal(result, exp) - def test_shift(self): # This is tested in test_arithmetic pass diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index d7bdd18f48523..7bcfe13270627 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -239,17 +239,6 @@ def test_infer_freq(self, freq): tm.assert_index_equal(idx, result) assert result.freq == freq - def test_nat_new(self): - - idx = pd.timedelta_range('1', freq='D', periods=5, name='x') - result = idx._nat_new() - exp = pd.TimedeltaIndex([pd.NaT] * 5, name='x') - tm.assert_index_equal(result, exp) - - result = idx._nat_new(box=False) - exp = np.array([iNaT] * 5, dtype=np.int64) - tm.assert_numpy_array_equal(result, exp) - def test_shift(self): pass # handled in test_arithmetic.py From b96bd933be3e2f027d0882e3d9da89ceaf9c6be6 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 15 Oct 2018 11:54:30 -0700 Subject: [PATCH 4/5] Flake8 fixup remove unused imports --- pandas/tests/indexes/datetimes/test_ops.py | 1 - pandas/tests/indexes/timedeltas/test_ops.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index ec9c293bbe988..1ac8ec9eec1cd 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -4,7 +4,6 @@ from datetime import datetime import pandas as pd -import pandas._libs.tslib as tslib import pandas.util.testing as tm from pandas import (DatetimeIndex, PeriodIndex, Series, Timestamp, date_range, _np_version_under1p10, Index, diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index 7bcfe13270627..d3235dd68a735 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -9,7 +9,6 @@ from pandas import (Series, Timedelta, Timestamp, TimedeltaIndex, timedelta_range, _np_version_under1p10) -from pandas._libs.tslib import iNaT from pandas.tests.test_base import Ops from pandas.tseries.offsets import Day, Hour from pandas.core.dtypes.generic import ABCDateOffset From 6ed0694599f87de1833d3d4aab4e24bba1aa9df7 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 15 Oct 2018 13:49:37 -0700 Subject: [PATCH 5/5] implement semi_shallow_copy, de-duplicate add_delta --- pandas/core/arrays/datetimelike.py | 48 ++++++++++++++++++++++++++---- pandas/core/arrays/datetimes.py | 26 ---------------- pandas/core/arrays/period.py | 31 ------------------- pandas/core/arrays/timedeltas.py | 26 ---------------- 4 files changed, 43 insertions(+), 88 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 951cc0b14ef3f..31828d807af39 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -101,6 +101,15 @@ def _shallow_copy(self, values=None, **kwargs): attributes['dtype'] = self.dtype return self._simple_new(values, **attributes) + def _semi_shallow_copy(self, values): + # similar to shallow_copy, but with freq="infer" + if is_period_dtype(self): + return self._shallow_copy(values) + elif is_timedelta64_dtype(self): + return type(self)(values, freq='infer') + else: + return type(self)(values, tz=self.tz, freq="infer") + class DatetimeLikeArrayMixin(ExtensionOpsMixin, AttributesMixin): """ @@ -339,8 +348,38 @@ def _sub_period(self, other): def _add_offset(self, offset): raise com.AbstractMethodError(self) - def _add_delta(self, other): - raise com.AbstractMethodError(self) + def _add_delta(self, delta): + """ + Add a timedelta-like, DateOffset, or TimedeltaIndex-like object + to self. + + Parameters + ---------- + delta : {timedelta, np.timedelta64, DateOffset, + TimedeltaIndex, ndarray[timedelta64]} + + Returns + ------- + result : same type as self + + Notes + ----- + The result's name is set outside of _add_delta by the calling + method (__add__ or __sub__) + """ + if is_period_dtype(self) and not isinstance(self.freq, Tick): + # We cannot add timedelta-like to non-tick PeriodArray + raise IncompatibleFrequency("Input has different freq from " + "{cls}(freq={freqstr})" + .format(cls=type(self).__name__, + freqstr=self.freqstr)) + + if isinstance(delta, (Tick, timedelta, np.timedelta64)): + new_values = self._add_delta_td(delta) + elif is_timedelta64_dtype(delta): + new_values = self._add_delta_tdi(delta) + + return self._semi_shallow_copy(new_values) def _add_delta_td(self, other): """ @@ -350,8 +389,7 @@ def _add_delta_td(self, other): inc = delta_to_nanoseconds(other) new_values = checked_add_with_arr(self.asi8, inc, arr_mask=self._isnan).view('i8') - if self.hasnans: - new_values[self._isnan] = iNaT + new_values = self._maybe_mask_results(new_values, fill_value=iNaT) return new_values.view('i8') def _add_delta_tdi(self, other): @@ -462,7 +500,7 @@ def _addsub_int_array(self, other, op): res_values = checked_add_with_arr(self.asi8, other, arr_mask=self._isnan) res_values = res_values.view('i8') - res_values[self._isnan] = iNaT + res_values = self._maybe_mask_results(res_values, fill_value=iNaT) return self._from_ordinals(res_values, freq=self.freq) elif self.freq is None: diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 65f17c5b48ce6..630a875dd7eae 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -487,32 +487,6 @@ def _sub_datelike(self, other): fill_value=iNaT) return result.view('timedelta64[ns]') - def _add_delta(self, delta): - """ - Add a timedelta-like, DateOffset, or TimedeltaIndex-like object - to self. - - Parameters - ---------- - delta : {timedelta, np.timedelta64, DateOffset, - TimedeltaIndex, ndarray[timedelta64]} - - Returns - ------- - result : same type as self - - Notes - ----- - The result's name is set outside of _add_delta by the calling - method (__add__ or __sub__) - """ - if isinstance(delta, (Tick, timedelta, np.timedelta64)): - new_values = self._add_delta_td(delta) - elif is_timedelta64_dtype(delta): - new_values = self._add_delta_tdi(delta) - - return type(self)(new_values, tz=self.tz, freq='infer') - # ----------------------------------------------------------------- # Timezone Conversion and Localization Methods diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 4af8fb92387d8..fd39080930fef 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -378,37 +378,6 @@ def _add_delta_tdi(self, other): delta = self._check_timedeltalike_freq_compat(other) return self._addsub_int_array(delta, operator.add) - def _add_delta(self, other): - """ - Add a timedelta-like, Tick, or TimedeltaIndex-like object - to self. - - Parameters - ---------- - other : {timedelta, np.timedelta64, Tick, - TimedeltaIndex, ndarray[timedelta64]} - - Returns - ------- - result : same type as self - """ - if not isinstance(self.freq, Tick): - # We cannot add timedelta-like to non-tick PeriodArray - raise IncompatibleFrequency("Input has different freq from " - "{cls}(freq={freqstr})" - .format(cls=type(self).__name__, - freqstr=self.freqstr)) - - # TODO: standardize across datetimelike subclasses whether to return - # i8 view or _shallow_copy - if isinstance(other, (Tick, timedelta, np.timedelta64)): - new_values = self._add_delta_td(other) - elif is_timedelta64_dtype(other): - # ndarray[timedelta64] or TimedeltaArray/index - new_values = self._add_delta_tdi(other) - - return self._shallow_copy(new_values) - @deprecate_kwarg(old_arg_name='n', new_arg_name='periods') def shift(self, periods): """ diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 30553762b0c6e..e7bca8926e1d9 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -196,32 +196,6 @@ def _sub_datelike(self, other): raise TypeError("cannot subtract a datelike from a {cls}" .format(cls=type(self).__name__)) - def _add_delta(self, delta): - """ - Add a timedelta-like, Tick, or TimedeltaIndex-like object - to self. - - Parameters - ---------- - delta : timedelta, np.timedelta64, Tick, TimedeltaArray, TimedeltaIndex - - Returns - ------- - result : same type as self - - Notes - ----- - The result's name is set outside of _add_delta by the calling - method (__add__ or __sub__) - """ - if isinstance(delta, (Tick, timedelta, np.timedelta64)): - new_values = self._add_delta_td(delta) - elif is_timedelta64_dtype(delta): - # ndarray[timedelta64] --> wrap in TimedeltaArray/Index - new_values = self._add_delta_tdi(delta) - - return type(self)(new_values, freq='infer') - def _add_datelike(self, other): # adding a timedeltaindex to a datetimelike from pandas.core.arrays import DatetimeArrayMixin