From a3e7ebed26f5a063a7098f7c85fba15d0437b4b1 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 15 Feb 2021 10:49:30 -0800 Subject: [PATCH] REF: remove unnecessary Block attrs --- pandas/core/internals/blocks.py | 33 ++++++++++----------------------- pandas/core/internals/concat.py | 3 --- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 3c27e34dcbcf6..ebed6eb325a65 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -101,9 +101,6 @@ class Block(PandasObject): __slots__ = ["_mgr_locs", "values", "ndim"] is_numeric = False is_float = False - is_datetime = False - is_datetimetz = False - is_timedelta = False is_bool = False is_object = False is_extension = False @@ -214,11 +211,6 @@ def is_view(self) -> bool: def is_categorical(self) -> bool: return self._holder is Categorical - @property - def is_datelike(self) -> bool: - """ return True if I am a non-datelike """ - return self.is_datetime or self.is_timedelta - def external_values(self): """ The array that Series.values returns (public attribute). @@ -549,7 +541,8 @@ def _maybe_downcast(self, blocks: List[Block], downcast=None) -> List[Block]: # no need to downcast our float # unless indicated - if downcast is None and (self.is_float or self.is_datelike): + if downcast is None and self.dtype.kind in ["f", "m", "M"]: + # TODO: complex? more generally, self._can_hold_na? return blocks return extend_blocks([b.downcast(downcast) for b in blocks]) @@ -636,13 +629,12 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"): raise newb = self.make_block(new_values) - if newb.is_numeric and self.is_numeric: - if newb.shape != self.shape: - raise TypeError( - f"cannot set astype for copy = [{copy}] for dtype " - f"({self.dtype.name} [{self.shape}]) to different shape " - f"({newb.dtype.name} [{newb.shape}])" - ) + if newb.shape != self.shape: + raise TypeError( + f"cannot set astype for copy = [{copy}] for dtype " + f"({self.dtype.name} [{self.shape}]) to different shape " + f"({newb.dtype.name} [{newb.shape}])" + ) return newb def _astype(self, dtype: DtypeObj, copy: bool) -> ArrayLike: @@ -2035,7 +2027,6 @@ def where(self, other, cond, errors="raise", axis: int = 0) -> List[Block]: class DatetimeBlock(DatetimeLikeBlockMixin): __slots__ = () - is_datetime = True @property def _can_hold_na(self): @@ -2081,7 +2072,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock): values: DatetimeArray __slots__ = () - is_datetimetz = True is_extension = True internal_values = Block.internal_values @@ -2160,10 +2150,8 @@ def get_values(self, dtype: Optional[DtypeObj] = None) -> np.ndarray: def external_values(self): # NB: this is different from np.asarray(self.values), since that # return an object-dtype ndarray of Timestamps. - if self.is_datetimetz: - # avoid FutureWarning in .astype in casting from dt64t to dt64 - return self.values._data - return np.asarray(self.values.astype("datetime64[ns]", copy=False)) + # Avoid FutureWarning in .astype in casting from dt64t to dt64 + return self.values._data def fillna( self, value, limit=None, inplace: bool = False, downcast=None @@ -2203,7 +2191,6 @@ def _check_ndim(self, values, ndim): class TimeDeltaBlock(DatetimeLikeBlockMixin): __slots__ = () - is_timedelta = True _can_hold_na = True is_numeric = False fill_value = np.timedelta64("NaT", "ns") diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index a2c930f6d9b22..cc0ff308a990a 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -12,7 +12,6 @@ from pandas.core.dtypes.cast import ensure_dtype_can_hold_na, find_common_type from pandas.core.dtypes.common import ( - is_categorical_dtype, is_datetime64tz_dtype, is_dtype_equal, is_extension_array_dtype, @@ -297,8 +296,6 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike: # TODO(EA2D): special case unneeded with 2D EAs i8values = np.full(self.shape[1], fill_value.value) return DatetimeArray(i8values, dtype=empty_dtype) - elif is_categorical_dtype(blk_dtype): - pass elif is_extension_array_dtype(blk_dtype): pass elif is_extension_array_dtype(empty_dtype):