Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: remove unnecessary DatetimeTZBlock.fillna #37040

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,13 +2090,7 @@ def _can_hold_element(self, element: Any) -> bool:
class DatetimeLikeBlockMixin(Block):
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""

@property
def _holder(self):
return DatetimeArray

@property
def fill_value(self):
return np.datetime64("NaT", "ns")
_can_hold_na = True

def get_values(self, dtype=None):
"""
Expand Down Expand Up @@ -2162,10 +2156,8 @@ def to_native_types(self, na_rep="NaT", **kwargs):
class DatetimeBlock(DatetimeLikeBlockMixin):
__slots__ = ()
is_datetime = True

@property
def _can_hold_na(self):
return True
_holder = DatetimeArray
fill_value = np.datetime64("NaT", "ns")

def _maybe_coerce_values(self, values):
"""
Expand Down Expand Up @@ -2256,15 +2248,16 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
is_extension = True

internal_values = Block.internal_values

_holder = DatetimeBlock._holder
_can_hold_element = DatetimeBlock._can_hold_element
to_native_types = DatetimeBlock.to_native_types
diff = DatetimeBlock.diff
fill_value = np.datetime64("NaT", "ns")
array_values = ExtensionBlock.array_values
fillna = DatetimeBlock.fillna # i.e. Block.fillna
fill_value = DatetimeBlock.fill_value
_can_hold_na = DatetimeBlock._can_hold_na

@property
def _holder(self):
return DatetimeArray
array_values = ExtensionBlock.array_values

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

def fillna(self, value, limit=None, inplace=False, downcast=None):
# We support filling a DatetimeTZ with a `value` whose timezone
# is different by coercing to object.
if self._can_hold_element(value):
return super().fillna(value, limit, inplace, downcast)

# different timezones, or a non-tz
return self.astype(object).fillna(
value, limit=limit, inplace=inplace, downcast=downcast
)

def quantile(self, qs, interpolation="linear", axis=0):
naive = self.values.view("M8[ns]")

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


class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
class TimeDeltaBlock(DatetimeLikeBlockMixin):
__slots__ = ()
is_timedelta = True
_can_hold_na = True
is_numeric = False
fill_value = np.timedelta64("NaT", "ns")

def _maybe_coerce_values(self, values):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ def _consolidate(blocks):
merged_blocks = _merge_blocks(
list(group_blocks), dtype=dtype, can_consolidate=_can_consolidate
)
new_blocks = extend_blocks(merged_blocks, new_blocks)
new_blocks.extend(merged_blocks)
return new_blocks


Expand Down