@@ -1968,7 +1968,13 @@ class IntBlock(NumericBlock):
1968
1968
class DatetimeLikeBlockMixin (HybridMixin , Block ):
1969
1969
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
1970
1970
1971
- _can_hold_na = True
1971
+ @property
1972
+ def _holder (self ):
1973
+ return DatetimeArray
1974
+
1975
+ @property
1976
+ def fill_value (self ):
1977
+ return np .datetime64 ("NaT" , "ns" )
1972
1978
1973
1979
def get_values (self , dtype : Optional [Dtype ] = None ):
1974
1980
"""
@@ -2052,8 +2058,10 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List["Block"]:
2052
2058
class DatetimeBlock (DatetimeLikeBlockMixin ):
2053
2059
__slots__ = ()
2054
2060
is_datetime = True
2055
- _holder = DatetimeArray
2056
- fill_value = np .datetime64 ("NaT" , "ns" )
2061
+
2062
+ @property
2063
+ def _can_hold_na (self ):
2064
+ return True
2057
2065
2058
2066
def _maybe_coerce_values (self , values ):
2059
2067
"""
@@ -2099,18 +2107,18 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
2099
2107
is_extension = True
2100
2108
2101
2109
internal_values = Block .internal_values
2102
-
2103
- _holder = DatetimeBlock ._holder
2104
2110
_can_hold_element = DatetimeBlock ._can_hold_element
2105
2111
to_native_types = DatetimeBlock .to_native_types
2106
2112
diff = DatetimeBlock .diff
2107
- fillna = DatetimeBlock .fillna # i.e. Block.fillna
2108
- fill_value = DatetimeBlock .fill_value
2109
- _can_hold_na = DatetimeBlock ._can_hold_na
2113
+ fill_value = np .datetime64 ("NaT" , "ns" )
2110
2114
where = DatetimeBlock .where
2111
2115
2112
2116
array_values = ExtensionBlock .array_values
2113
2117
2118
+ @property
2119
+ def _holder (self ):
2120
+ return DatetimeArray
2121
+
2114
2122
def _maybe_coerce_values (self , values ):
2115
2123
"""
2116
2124
Input validation for values passed to __init__. Ensure that
@@ -2175,6 +2183,17 @@ def external_values(self):
2175
2183
# return an object-dtype ndarray of Timestamps.
2176
2184
return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
2177
2185
2186
+ def fillna (self , value , limit = None , inplace = False , downcast = None ):
2187
+ # We support filling a DatetimeTZ with a `value` whose timezone
2188
+ # is different by coercing to object.
2189
+ if self ._can_hold_element (value ):
2190
+ return super ().fillna (value , limit , inplace , downcast )
2191
+
2192
+ # different timezones, or a non-tz
2193
+ return self .astype (object ).fillna (
2194
+ value , limit = limit , inplace = inplace , downcast = downcast
2195
+ )
2196
+
2178
2197
def quantile (self , qs , interpolation = "linear" , axis = 0 ):
2179
2198
naive = self .values .view ("M8[ns]" )
2180
2199
@@ -2211,9 +2230,11 @@ def _check_ndim(self, values, ndim):
2211
2230
return ndim
2212
2231
2213
2232
2214
- class TimeDeltaBlock (DatetimeLikeBlockMixin ):
2233
+ class TimeDeltaBlock (DatetimeLikeBlockMixin , IntBlock ):
2215
2234
__slots__ = ()
2216
2235
is_timedelta = True
2236
+ _can_hold_na = True
2237
+ is_numeric = False
2217
2238
fill_value = np .timedelta64 ("NaT" , "ns" )
2218
2239
2219
2240
def _maybe_coerce_values (self , values ):
0 commit comments