66
77import numpy as np
88
9- from pandas ._libs import algos , lib , tslibs
9+ from pandas ._libs import lib , tslibs
1010from pandas ._libs .tslibs import NaT , Timedelta , Timestamp , iNaT
1111from pandas ._libs .tslibs .fields import get_timedelta_field
1212from pandas ._libs .tslibs .timedeltas import (
1515from pandas .util ._decorators import Appender
1616
1717from pandas .core .dtypes .common import (
18- _TD_DTYPE , ensure_int64 , is_datetime64_dtype , is_float_dtype ,
18+ _NS_DTYPE , _TD_DTYPE , ensure_int64 , is_datetime64_dtype , is_float_dtype ,
1919 is_integer_dtype , is_list_like , is_object_dtype , is_scalar ,
2020 is_string_dtype , is_timedelta64_dtype )
21+ from pandas .core .dtypes .dtypes import DatetimeTZDtype
2122from pandas .core .dtypes .generic import (
2223 ABCDataFrame , ABCIndexClass , ABCSeries , ABCTimedeltaIndex )
2324from pandas .core .dtypes .missing import isna
2425
2526from pandas .core import ops
26- from pandas .core .algorithms import checked_add_with_arr , unique1d
27+ from pandas .core .algorithms import checked_add_with_arr
2728import pandas .core .common as com
2829
2930from pandas .tseries .frequencies import to_offset
@@ -90,7 +91,7 @@ def wrapper(self, other):
9091
9192 else :
9293 try :
93- other = type (self )(other )._data
94+ other = type (self ). _from_sequence (other )._data
9495 except (ValueError , TypeError ):
9596 return ops .invalid_comparison (self , other , op )
9697
@@ -112,6 +113,14 @@ def wrapper(self, other):
112113class TimedeltaArrayMixin (dtl .DatetimeLikeArrayMixin , dtl .TimelikeOps ):
113114 _typ = "timedeltaarray"
114115 __array_priority__ = 1000
116+ # define my properties & methods for delegation
117+ _other_ops = []
118+ _bool_ops = []
119+ _object_ops = ['freq' ]
120+ _field_ops = ['days' , 'seconds' , 'microseconds' , 'nanoseconds' ]
121+ _datetimelike_ops = _field_ops + _object_ops + _bool_ops
122+ _datetimelike_methods = ["to_pytimedelta" , "total_seconds" ,
123+ "round" , "floor" , "ceil" ]
115124
116125 # Needed so that NaT.__richcmp__(DateTimeArray) operates pointwise
117126 ndim = 1
@@ -222,21 +231,6 @@ def _validate_fill_value(self, fill_value):
222231 "Got '{got}'." .format (got = fill_value ))
223232 return fill_value
224233
225- # monotonicity/uniqueness properties are called via frequencies.infer_freq,
226- # see GH#23789
227-
228- @property
229- def _is_monotonic_increasing (self ):
230- return algos .is_monotonic (self .asi8 , timelike = True )[0 ]
231-
232- @property
233- def _is_monotonic_decreasing (self ):
234- return algos .is_monotonic (self .asi8 , timelike = True )[1 ]
235-
236- @property
237- def _is_unique (self ):
238- return len (unique1d (self .asi8 )) == len (self )
239-
240234 # ----------------------------------------------------------------
241235 # Arithmetic Methods
242236
@@ -262,8 +256,8 @@ def _add_delta(self, delta):
262256 -------
263257 result : TimedeltaArray
264258 """
265- new_values = dtl . DatetimeLikeArrayMixin . _add_delta ( self , delta )
266- return type (self )(new_values , freq = 'infer' )
259+ new_values = super ( TimedeltaArrayMixin , self ). _add_delta ( delta )
260+ return type (self ). _from_sequence (new_values , freq = 'infer' )
267261
268262 def _add_datetime_arraylike (self , other ):
269263 """
@@ -293,7 +287,8 @@ def _add_datetimelike_scalar(self, other):
293287 result = checked_add_with_arr (i8 , other .value ,
294288 arr_mask = self ._isnan )
295289 result = self ._maybe_mask_results (result )
296- return DatetimeArrayMixin (result , tz = other .tz , freq = self .freq )
290+ dtype = DatetimeTZDtype (tz = other .tz ) if other .tz else _NS_DTYPE
291+ return DatetimeArrayMixin (result , dtype = dtype , freq = self .freq )
297292
298293 def _addsub_offset_array (self , other , op ):
299294 # Add or subtract Array-like of DateOffset objects
0 commit comments