Skip to content

Commit 58f7468

Browse files
authored
CLN: remove unnecessary DatetimeTZBlock.fillna (#37040)
1 parent 70a14cd commit 58f7468

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

pandas/core/internals/blocks.py

+10-30
Original file line numberDiff line numberDiff line change
@@ -2090,13 +2090,7 @@ def _can_hold_element(self, element: Any) -> bool:
20902090
class DatetimeLikeBlockMixin(Block):
20912091
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
20922092

2093-
@property
2094-
def _holder(self):
2095-
return DatetimeArray
2096-
2097-
@property
2098-
def fill_value(self):
2099-
return np.datetime64("NaT", "ns")
2093+
_can_hold_na = True
21002094

21012095
def get_values(self, dtype=None):
21022096
"""
@@ -2162,10 +2156,8 @@ def to_native_types(self, na_rep="NaT", **kwargs):
21622156
class DatetimeBlock(DatetimeLikeBlockMixin):
21632157
__slots__ = ()
21642158
is_datetime = True
2165-
2166-
@property
2167-
def _can_hold_na(self):
2168-
return True
2159+
_holder = DatetimeArray
2160+
fill_value = np.datetime64("NaT", "ns")
21692161

21702162
def _maybe_coerce_values(self, values):
21712163
"""
@@ -2256,15 +2248,16 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
22562248
is_extension = True
22572249

22582250
internal_values = Block.internal_values
2251+
2252+
_holder = DatetimeBlock._holder
22592253
_can_hold_element = DatetimeBlock._can_hold_element
22602254
to_native_types = DatetimeBlock.to_native_types
22612255
diff = DatetimeBlock.diff
2262-
fill_value = np.datetime64("NaT", "ns")
2263-
array_values = ExtensionBlock.array_values
2256+
fillna = DatetimeBlock.fillna # i.e. Block.fillna
2257+
fill_value = DatetimeBlock.fill_value
2258+
_can_hold_na = DatetimeBlock._can_hold_na
22642259

2265-
@property
2266-
def _holder(self):
2267-
return DatetimeArray
2260+
array_values = ExtensionBlock.array_values
22682261

22692262
def _maybe_coerce_values(self, values):
22702263
"""
@@ -2330,17 +2323,6 @@ def external_values(self):
23302323
# return an object-dtype ndarray of Timestamps.
23312324
return np.asarray(self.values.astype("datetime64[ns]", copy=False))
23322325

2333-
def fillna(self, value, limit=None, inplace=False, downcast=None):
2334-
# We support filling a DatetimeTZ with a `value` whose timezone
2335-
# is different by coercing to object.
2336-
if self._can_hold_element(value):
2337-
return super().fillna(value, limit, inplace, downcast)
2338-
2339-
# different timezones, or a non-tz
2340-
return self.astype(object).fillna(
2341-
value, limit=limit, inplace=inplace, downcast=downcast
2342-
)
2343-
23442326
def quantile(self, qs, interpolation="linear", axis=0):
23452327
naive = self.values.view("M8[ns]")
23462328

@@ -2355,11 +2337,9 @@ def quantile(self, qs, interpolation="linear", axis=0):
23552337
return self.make_block_same_class(aware, ndim=res_blk.ndim)
23562338

23572339

2358-
class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
2340+
class TimeDeltaBlock(DatetimeLikeBlockMixin):
23592341
__slots__ = ()
23602342
is_timedelta = True
2361-
_can_hold_na = True
2362-
is_numeric = False
23632343
fill_value = np.timedelta64("NaT", "ns")
23642344

23652345
def _maybe_coerce_values(self, values):

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ def _consolidate(blocks):
18751875
merged_blocks = _merge_blocks(
18761876
list(group_blocks), dtype=dtype, can_consolidate=_can_consolidate
18771877
)
1878-
new_blocks = extend_blocks(merged_blocks, new_blocks)
1878+
new_blocks.extend(merged_blocks)
18791879
return new_blocks
18801880

18811881

0 commit comments

Comments
 (0)