Skip to content

REF: remove unnecessary Block attrs #39824

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

Merged
merged 4 commits into from
Feb 16, 2021
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
28 changes: 9 additions & 19 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,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
Expand Down Expand Up @@ -213,11 +210,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).
Expand Down Expand Up @@ -547,7 +539,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])
Expand Down Expand Up @@ -634,13 +627,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:
Expand Down Expand Up @@ -2089,7 +2081,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
values: DatetimeArray

__slots__ = ()
is_datetimetz = True
is_extension = True

_holder = DatetimeArray
Expand Down Expand Up @@ -2167,7 +2158,7 @@ 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.
# avoid FutureWarning in .astype in casting from dt64t to dt64
# Avoid FutureWarning in .astype in casting from dt64tz to dt64
return self.values._data

def fillna(
Expand Down Expand Up @@ -2208,7 +2199,6 @@ def _check_ndim(self, values, ndim):

class TimeDeltaBlock(DatetimeLikeBlockMixin):
__slots__ = ()
is_timedelta = True
_can_hold_na = True
is_numeric = False
_holder = TimedeltaArray
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -295,8 +294,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):
Expand Down