@@ -166,6 +166,8 @@ def dtype(self) -> np.dtype:
166
166
# ----------------------------------------------------------------
167
167
# Constructors
168
168
169
+ _freq = None
170
+
169
171
def __init__ (self , values , dtype = TD64NS_DTYPE , freq = lib .no_default , copy = False ):
170
172
values = extract_array (values )
171
173
@@ -182,7 +184,7 @@ def __init__(self, values, dtype=TD64NS_DTYPE, freq=lib.no_default, copy=False):
182
184
elif freq and values .freq :
183
185
freq = to_offset (freq )
184
186
freq , _ = dtl .validate_inferred_freq (freq , values .freq , False )
185
- values = values ._data
187
+ values = values ._ndarray
186
188
187
189
if not isinstance (values , np .ndarray ):
188
190
msg = (
@@ -214,7 +216,7 @@ def __init__(self, values, dtype=TD64NS_DTYPE, freq=lib.no_default, copy=False):
214
216
if freq :
215
217
freq = to_offset (freq )
216
218
217
- self ._data = values
219
+ self ._ndarray = values
218
220
self ._dtype = dtype
219
221
self ._freq = freq
220
222
@@ -232,7 +234,7 @@ def _simple_new(
232
234
values = values .view (TD64NS_DTYPE )
233
235
234
236
result = object .__new__ (cls )
235
- result ._data = values
237
+ result ._ndarray = values
236
238
result ._freq = to_offset (freq )
237
239
result ._dtype = TD64NS_DTYPE
238
240
return result
@@ -344,7 +346,7 @@ def astype(self, dtype, copy: bool = True):
344
346
dtype = pandas_dtype (dtype )
345
347
346
348
if dtype .kind == "m" :
347
- return astype_td64_unit_conversion (self ._data , dtype , copy = copy )
349
+ return astype_td64_unit_conversion (self ._ndarray , dtype , copy = copy )
348
350
349
351
return dtl .DatetimeLikeArrayMixin .astype (self , dtype , copy = copy )
350
352
@@ -418,8 +420,8 @@ def _formatter(self, boxed=False):
418
420
def _format_native_types (self , na_rep = "NaT" , date_format = None , ** kwargs ):
419
421
from pandas .io .formats .format import get_format_timedelta64
420
422
421
- formatter = get_format_timedelta64 (self ._data , na_rep )
422
- return np .array ([formatter (x ) for x in self ._data ])
423
+ formatter = get_format_timedelta64 (self ._ndarray , na_rep )
424
+ return np .array ([formatter (x ) for x in self ._ndarray ])
423
425
424
426
# ----------------------------------------------------------------
425
427
# Arithmetic Methods
@@ -488,7 +490,7 @@ def _addsub_object_array(self, other, op):
488
490
def __mul__ (self , other ) -> TimedeltaArray :
489
491
if is_scalar (other ):
490
492
# numpy will accept float and int, raise TypeError for others
491
- result = self ._data * other
493
+ result = self ._ndarray * other
492
494
freq = None
493
495
if self .freq is not None and not isna (other ):
494
496
freq = self .freq * other
@@ -511,7 +513,7 @@ def __mul__(self, other) -> TimedeltaArray:
511
513
return type (self )(result )
512
514
513
515
# numpy will accept float or int dtype, raise TypeError for others
514
- result = self ._data * other
516
+ result = self ._ndarray * other
515
517
return type (self )(result )
516
518
517
519
__rmul__ = __mul__
@@ -529,11 +531,11 @@ def __truediv__(self, other):
529
531
return result
530
532
531
533
# otherwise, dispatch to Timedelta implementation
532
- return self ._data / other
534
+ return self ._ndarray / other
533
535
534
536
elif lib .is_scalar (other ):
535
537
# assume it is numeric
536
- result = self ._data / other
538
+ result = self ._ndarray / other
537
539
freq = None
538
540
if self .freq is not None :
539
541
# Tick division is not implemented, so operate on Timedelta
@@ -549,7 +551,7 @@ def __truediv__(self, other):
549
551
550
552
elif is_timedelta64_dtype (other .dtype ):
551
553
# let numpy handle it
552
- return self ._data / other
554
+ return self ._ndarray / other
553
555
554
556
elif is_object_dtype (other .dtype ):
555
557
# We operate on raveled arrays to avoid problems in inference
@@ -571,7 +573,7 @@ def __truediv__(self, other):
571
573
return result
572
574
573
575
else :
574
- result = self ._data / other
576
+ result = self ._ndarray / other
575
577
return type (self )(result )
576
578
577
579
@unpack_zerodim_and_defer ("__rtruediv__" )
@@ -586,7 +588,7 @@ def __rtruediv__(self, other):
586
588
return result
587
589
588
590
# otherwise, dispatch to Timedelta implementation
589
- return other / self ._data
591
+ return other / self ._ndarray
590
592
591
593
elif lib .is_scalar (other ):
592
594
raise TypeError (
@@ -602,7 +604,7 @@ def __rtruediv__(self, other):
602
604
603
605
elif is_timedelta64_dtype (other .dtype ):
604
606
# let numpy handle it
605
- return other / self ._data
607
+ return other / self ._ndarray
606
608
607
609
elif is_object_dtype (other .dtype ):
608
610
# Note: unlike in __truediv__, we do not _need_ to do type
@@ -629,7 +631,7 @@ def __floordiv__(self, other):
629
631
return result
630
632
631
633
# dispatch to Timedelta implementation
632
- result = other .__rfloordiv__ (self ._data )
634
+ result = other .__rfloordiv__ (self ._ndarray )
633
635
return result
634
636
635
637
# at this point we should only have numeric scalars; anything
@@ -673,7 +675,7 @@ def __floordiv__(self, other):
673
675
return result
674
676
675
677
elif is_integer_dtype (other .dtype ) or is_float_dtype (other .dtype ):
676
- result = self ._data // other
678
+ result = self ._ndarray // other
677
679
return type (self )(result )
678
680
679
681
else :
@@ -693,7 +695,7 @@ def __rfloordiv__(self, other):
693
695
return result
694
696
695
697
# dispatch to Timedelta implementation
696
- result = other .__floordiv__ (self ._data )
698
+ result = other .__floordiv__ (self ._ndarray )
697
699
return result
698
700
699
701
raise TypeError (
@@ -763,15 +765,15 @@ def __rdivmod__(self, other):
763
765
764
766
def __neg__ (self ) -> TimedeltaArray :
765
767
if self .freq is not None :
766
- return type (self )(- self ._data , freq = - self .freq )
767
- return type (self )(- self ._data )
768
+ return type (self )(- self ._ndarray , freq = - self .freq )
769
+ return type (self )(- self ._ndarray )
768
770
769
771
def __pos__ (self ) -> TimedeltaArray :
770
- return type (self )(self ._data , freq = self .freq )
772
+ return type (self )(self ._ndarray , freq = self .freq )
771
773
772
774
def __abs__ (self ) -> TimedeltaArray :
773
775
# Note: freq is not preserved
774
- return type (self )(np .abs (self ._data ))
776
+ return type (self )(np .abs (self ._ndarray ))
775
777
776
778
# ----------------------------------------------------------------
777
779
# Conversion Methods - Vectorized analogues of Timedelta methods
@@ -949,9 +951,12 @@ def sequence_to_td64ns(data, copy=False, unit=None, errors="raise"):
949
951
data = np .array (data , copy = False )
950
952
elif isinstance (data , ABCSeries ):
951
953
data = data ._values
952
- elif isinstance (data , (ABCTimedeltaIndex , TimedeltaArray )):
954
+ elif isinstance (data , ABCTimedeltaIndex ):
955
+ inferred_freq = data .freq
956
+ data = data ._data ._ndarray
957
+ elif isinstance (data , TimedeltaArray ):
953
958
inferred_freq = data .freq
954
- data = data ._data
959
+ data = data ._ndarray
955
960
elif isinstance (data , IntegerArray ):
956
961
data = data .to_numpy ("int64" , na_value = tslibs .iNaT )
957
962
elif is_categorical_dtype (data .dtype ):
0 commit comments