@@ -2048,6 +2048,21 @@ def shift(self, periods: int, axis: int = 0, fill_value: Any = None) -> List[Blo
2048
2048
new_values = values .shift (periods , fill_value = fill_value , axis = axis )
2049
2049
return [self .make_block_same_class (new_values )]
2050
2050
2051
+ def fillna (
2052
+ self , value , limit = None , inplace : bool = False , downcast = None
2053
+ ) -> List [Block ]:
2054
+
2055
+ if not self ._can_hold_element (value ) and self .dtype .kind != "m" :
2056
+ # We support filling a DatetimeTZ with a `value` whose timezone
2057
+ # is different by coercing to object.
2058
+ # TODO: don't special-case td64
2059
+ return self .astype (object ).fillna (value , limit , inplace , downcast )
2060
+
2061
+ values = self .array_values ()
2062
+ values = values if inplace else values .copy ()
2063
+ new_values = values .fillna (value = value , limit = limit )
2064
+ return [self .make_block_same_class (values = new_values )]
2065
+
2051
2066
2052
2067
class DatetimeLikeBlockMixin (NDArrayBackedExtensionBlock ):
2053
2068
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
@@ -2134,6 +2149,7 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
2134
2149
fill_value = NaT
2135
2150
where = DatetimeBlock .where
2136
2151
putmask = DatetimeLikeBlockMixin .putmask
2152
+ fillna = DatetimeLikeBlockMixin .fillna
2137
2153
2138
2154
array_values = ExtensionBlock .array_values
2139
2155
@@ -2172,19 +2188,6 @@ def external_values(self):
2172
2188
# Avoid FutureWarning in .astype in casting from dt64tz to dt64
2173
2189
return self .values ._data
2174
2190
2175
- def fillna (
2176
- self , value , limit = None , inplace : bool = False , downcast = None
2177
- ) -> List [Block ]:
2178
- # We support filling a DatetimeTZ with a `value` whose timezone
2179
- # is different by coercing to object.
2180
- if self ._can_hold_element (value ):
2181
- return super ().fillna (value , limit , inplace , downcast )
2182
-
2183
- # different timezones, or a non-tz
2184
- return self .astype (object ).fillna (
2185
- value , limit = limit , inplace = inplace , downcast = downcast
2186
- )
2187
-
2188
2191
2189
2192
class TimeDeltaBlock (DatetimeLikeBlockMixin ):
2190
2193
__slots__ = ()
@@ -2194,14 +2197,6 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin):
2194
2197
fill_value = np .timedelta64 ("NaT" , "ns" )
2195
2198
_dtype = fill_value .dtype
2196
2199
2197
- def fillna (
2198
- self , value , limit = None , inplace : bool = False , downcast = None
2199
- ) -> List [Block ]:
2200
- values = self .array_values ()
2201
- values = values if inplace else values .copy ()
2202
- new_values = values .fillna (value = value , limit = limit )
2203
- return [self .make_block_same_class (values = new_values )]
2204
-
2205
2200
2206
2201
class ObjectBlock (Block ):
2207
2202
__slots__ = ()
0 commit comments