@@ -2148,7 +2148,13 @@ def _can_hold_element(self, element: Any) -> bool:
2148
2148
class DatetimeLikeBlockMixin (Block ):
2149
2149
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
2150
2150
2151
- _can_hold_na = True
2151
+ @property
2152
+ def _holder (self ):
2153
+ return DatetimeArray
2154
+
2155
+ @property
2156
+ def fill_value (self ):
2157
+ return np .datetime64 ("NaT" , "ns" )
2152
2158
2153
2159
def get_values (self , dtype = None ):
2154
2160
"""
@@ -2216,8 +2222,10 @@ def to_native_types(self, na_rep="NaT", **kwargs):
2216
2222
class DatetimeBlock (DatetimeLikeBlockMixin ):
2217
2223
__slots__ = ()
2218
2224
is_datetime = True
2219
- _holder = DatetimeArray
2220
- fill_value = np .datetime64 ("NaT" , "ns" )
2225
+
2226
+ @property
2227
+ def _can_hold_na (self ):
2228
+ return True
2221
2229
2222
2230
def _maybe_coerce_values (self , values ):
2223
2231
"""
@@ -2308,17 +2316,17 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
2308
2316
is_extension = True
2309
2317
2310
2318
internal_values = Block .internal_values
2311
-
2312
- _holder = DatetimeBlock ._holder
2313
2319
_can_hold_element = DatetimeBlock ._can_hold_element
2314
2320
to_native_types = DatetimeBlock .to_native_types
2315
2321
diff = DatetimeBlock .diff
2316
- fillna = DatetimeBlock .fillna # i.e. Block.fillna
2317
- fill_value = DatetimeBlock .fill_value
2318
- _can_hold_na = DatetimeBlock ._can_hold_na
2322
+ fill_value = np .datetime64 ("NaT" , "ns" )
2319
2323
2320
2324
array_values = ExtensionBlock .array_values
2321
2325
2326
+ @property
2327
+ def _holder (self ):
2328
+ return DatetimeArray
2329
+
2322
2330
def _maybe_coerce_values (self , values ):
2323
2331
"""
2324
2332
Input validation for values passed to __init__. Ensure that
@@ -2383,6 +2391,17 @@ def external_values(self):
2383
2391
# return an object-dtype ndarray of Timestamps.
2384
2392
return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
2385
2393
2394
+ def fillna (self , value , limit = None , inplace = False , downcast = None ):
2395
+ # We support filling a DatetimeTZ with a `value` whose timezone
2396
+ # is different by coercing to object.
2397
+ if self ._can_hold_element (value ):
2398
+ return super ().fillna (value , limit , inplace , downcast )
2399
+
2400
+ # different timezones, or a non-tz
2401
+ return self .astype (object ).fillna (
2402
+ value , limit = limit , inplace = inplace , downcast = downcast
2403
+ )
2404
+
2386
2405
def quantile (self , qs , interpolation = "linear" , axis = 0 ):
2387
2406
naive = self .values .view ("M8[ns]" )
2388
2407
@@ -2419,9 +2438,11 @@ def _check_ndim(self, values, ndim):
2419
2438
return ndim
2420
2439
2421
2440
2422
- class TimeDeltaBlock (DatetimeLikeBlockMixin ):
2441
+ class TimeDeltaBlock (DatetimeLikeBlockMixin , IntBlock ):
2423
2442
__slots__ = ()
2424
2443
is_timedelta = True
2444
+ _can_hold_na = True
2445
+ is_numeric = False
2425
2446
fill_value = np .timedelta64 ("NaT" , "ns" )
2426
2447
2427
2448
def _maybe_coerce_values (self , values ):
0 commit comments