Skip to content

Commit fb81567

Browse files
authored
REF: remove unnecessary Block attrs (#39824)
1 parent d01561f commit fb81567

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

pandas/core/internals/blocks.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ class Block(PandasObject):
128128
__slots__ = ["_mgr_locs", "values", "ndim"]
129129
is_numeric = False
130130
is_float = False
131-
is_datetime = False
132-
is_datetimetz = False
133-
is_timedelta = False
134131
is_bool = False
135132
is_object = False
136133
is_extension = False
@@ -242,11 +239,6 @@ def is_view(self) -> bool:
242239
def is_categorical(self) -> bool:
243240
return self._holder is Categorical
244241

245-
@property
246-
def is_datelike(self) -> bool:
247-
""" return True if I am a non-datelike """
248-
return self.is_datetime or self.is_timedelta
249-
250242
def external_values(self):
251243
"""
252244
The array that Series.values returns (public attribute).
@@ -576,7 +568,8 @@ def _maybe_downcast(self, blocks: List[Block], downcast=None) -> List[Block]:
576568

577569
# no need to downcast our float
578570
# unless indicated
579-
if downcast is None and (self.is_float or self.is_datelike):
571+
if downcast is None and self.dtype.kind in ["f", "m", "M"]:
572+
# TODO: complex? more generally, self._can_hold_na?
580573
return blocks
581574

582575
return extend_blocks([b.downcast(downcast) for b in blocks])
@@ -663,13 +656,12 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
663656
raise
664657

665658
newb = self.make_block(new_values)
666-
if newb.is_numeric and self.is_numeric:
667-
if newb.shape != self.shape:
668-
raise TypeError(
669-
f"cannot set astype for copy = [{copy}] for dtype "
670-
f"({self.dtype.name} [{self.shape}]) to different shape "
671-
f"({newb.dtype.name} [{newb.shape}])"
672-
)
659+
if newb.shape != self.shape:
660+
raise TypeError(
661+
f"cannot set astype for copy = [{copy}] for dtype "
662+
f"({self.dtype.name} [{self.shape}]) to different shape "
663+
f"({newb.dtype.name} [{newb.shape}])"
664+
)
673665
return newb
674666

675667
def _astype(self, dtype: DtypeObj, copy: bool) -> ArrayLike:
@@ -2118,7 +2110,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
21182110
values: DatetimeArray
21192111

21202112
__slots__ = ()
2121-
is_datetimetz = True
21222113
is_extension = True
21232114

21242115
_holder = DatetimeArray
@@ -2196,7 +2187,7 @@ def get_values(self, dtype: Optional[DtypeObj] = None) -> np.ndarray:
21962187
def external_values(self):
21972188
# NB: this is different from np.asarray(self.values), since that
21982189
# return an object-dtype ndarray of Timestamps.
2199-
# avoid FutureWarning in .astype in casting from dt64t to dt64
2190+
# Avoid FutureWarning in .astype in casting from dt64tz to dt64
22002191
return self.values._data
22012192

22022193
def fillna(
@@ -2237,7 +2228,6 @@ def _check_ndim(self, values, ndim):
22372228

22382229
class TimeDeltaBlock(DatetimeLikeBlockMixin):
22392230
__slots__ = ()
2240-
is_timedelta = True
22412231
_can_hold_na = True
22422232
is_numeric = False
22432233
_holder = TimedeltaArray

pandas/core/internals/concat.py

-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
find_common_type,
2626
)
2727
from pandas.core.dtypes.common import (
28-
is_categorical_dtype,
2928
is_datetime64tz_dtype,
3029
is_dtype_equal,
3130
is_extension_array_dtype,
@@ -314,8 +313,6 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
314313
# TODO(EA2D): special case unneeded with 2D EAs
315314
i8values = np.full(self.shape[1], fill_value.value)
316315
return DatetimeArray(i8values, dtype=empty_dtype)
317-
elif is_categorical_dtype(blk_dtype):
318-
pass
319316
elif is_extension_array_dtype(blk_dtype):
320317
pass
321318
elif is_extension_array_dtype(empty_dtype):

0 commit comments

Comments
 (0)