Skip to content

CLN: dont special-case should_store, CategoricalBlock #36952

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 2 commits into from
Oct 8, 2020
Merged
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
29 changes: 4 additions & 25 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class Block(PandasObject):
is_timedelta = False
is_bool = False
is_object = False
is_categorical = False
is_extension = False
_can_hold_na = False
_can_consolidate = True
Expand Down Expand Up @@ -183,6 +182,10 @@ def is_view(self) -> bool:
""" return a boolean if I am possibly a view """
return self.values.base is not None

@property
def is_categorical(self) -> bool:
return self._holder is Categorical

@property
def is_datelike(self) -> bool:
""" return True if I am a non-datelike """
Expand Down Expand Up @@ -1652,12 +1655,6 @@ def iget(self, col):
raise IndexError(f"{self} only contains one item")
return self.values

def should_store(self, value: ArrayLike) -> bool:
"""
Can we set the given array-like value inplace?
"""
return isinstance(value, self._holder)

def set(self, locs, values):
assert locs.tolist() == [0]
self.values = values
Expand Down Expand Up @@ -2048,9 +2045,6 @@ def _can_hold_element(self, element: Any) -> bool:
element, (float, int, complex, np.float_, np.int_)
) and not isinstance(element, (bool, np.bool_))

def should_store(self, value: ArrayLike) -> bool:
return issubclass(value.dtype.type, np.complexfloating)


class IntBlock(NumericBlock):
__slots__ = ()
Expand Down Expand Up @@ -2216,7 +2210,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
_can_hold_element = DatetimeBlock._can_hold_element
to_native_types = DatetimeBlock.to_native_types
fill_value = np.datetime64("NaT", "ns")
should_store = Block.should_store
array_values = ExtensionBlock.array_values

@property
Expand Down Expand Up @@ -2687,20 +2680,6 @@ def _replace_coerce(

class CategoricalBlock(ExtensionBlock):
__slots__ = ()
is_categorical = True
_can_hold_na = True

should_store = Block.should_store

def __init__(self, values, placement, ndim=None):
# coerce to categorical if we can
values = extract_array(values)
assert isinstance(values, Categorical), type(values)
super().__init__(values, placement=placement, ndim=ndim)

@property
def _holder(self):
return Categorical

def replace(
self,
Expand Down