@@ -2607,6 +2607,7 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
2607
2607
is_timedelta = True
2608
2608
_can_hold_na = True
2609
2609
is_numeric = False
2610
+ fill_value = np .timedelta64 ("NaT" , "ns" )
2610
2611
2611
2612
def __init__ (self , values , placement , ndim = None ):
2612
2613
if values .dtype != _TD_DTYPE :
@@ -2627,15 +2628,11 @@ def _box_func(self):
2627
2628
def _can_hold_element (self , element ):
2628
2629
tipo = maybe_infer_dtype_type (element )
2629
2630
if tipo is not None :
2630
- # TODO: remove the np.int64 support once coerce_values and
2631
- # _try_coerce_args both coerce to m8[ns] and not i8.
2632
- return issubclass (tipo .type , (np .timedelta64 , np .int64 ))
2631
+ return issubclass (tipo .type , np .timedelta64 )
2633
2632
elif element is NaT :
2634
2633
return True
2635
2634
elif isinstance (element , (timedelta , np .timedelta64 )):
2636
2635
return True
2637
- elif is_integer (element ):
2638
- return element == tslibs .iNaT
2639
2636
return is_valid_nat_for_dtype (element , self .dtype )
2640
2637
2641
2638
def fillna (self , value , ** kwargs ):
@@ -2655,9 +2652,6 @@ def fillna(self, value, **kwargs):
2655
2652
value = Timedelta (value , unit = "s" )
2656
2653
return super ().fillna (value , ** kwargs )
2657
2654
2658
- def _coerce_values (self , values ):
2659
- return values .view ("i8" )
2660
-
2661
2655
def _try_coerce_args (self , other ):
2662
2656
"""
2663
2657
Coerce values and other to int64, with null values converted to
@@ -2673,13 +2667,12 @@ def _try_coerce_args(self, other):
2673
2667
"""
2674
2668
2675
2669
if is_valid_nat_for_dtype (other , self .dtype ):
2676
- other = tslibs .iNaT
2677
- elif is_integer (other ) and other == tslibs .iNaT :
2678
- pass
2670
+ other = np .timedelta64 ("NaT" , "ns" )
2679
2671
elif isinstance (other , (timedelta , np .timedelta64 )):
2680
- other = Timedelta (other ).value
2672
+ other = Timedelta (other ).to_timedelta64 ()
2681
2673
elif hasattr (other , "dtype" ) and is_timedelta64_dtype (other ):
2682
- other = other .astype ("i8" , copy = False ).view ("i8" )
2674
+ # TODO: can we get here with non-nano dtype?
2675
+ pass
2683
2676
else :
2684
2677
# coercion issues
2685
2678
# let higher levels handle
@@ -2693,7 +2686,7 @@ def _try_coerce_result(self, result):
2693
2686
mask = isna (result )
2694
2687
if result .dtype .kind in ["i" , "f" ]:
2695
2688
result = result .astype ("m8[ns]" )
2696
- result [mask ] = tslibs . iNaT
2689
+ result [mask ] = np . timedelta64 ( "NaT" , "ns" )
2697
2690
2698
2691
elif isinstance (result , (np .integer , np .float )):
2699
2692
result = self ._box_func (result )
0 commit comments