Skip to content

Commit f2ec69d

Browse files
authored
CLN: dont special-case should_store, CategoricalBlock (#36952)
1 parent 7eb6d2f commit f2ec69d

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

pandas/core/internals/blocks.py

+4-25
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class Block(PandasObject):
103103
is_timedelta = False
104104
is_bool = False
105105
is_object = False
106-
is_categorical = False
107106
is_extension = False
108107
_can_hold_na = False
109108
_can_consolidate = True
@@ -183,6 +182,10 @@ def is_view(self) -> bool:
183182
""" return a boolean if I am possibly a view """
184183
return self.values.base is not None
185184

185+
@property
186+
def is_categorical(self) -> bool:
187+
return self._holder is Categorical
188+
186189
@property
187190
def is_datelike(self) -> bool:
188191
""" return True if I am a non-datelike """
@@ -1654,12 +1657,6 @@ def iget(self, col):
16541657
raise IndexError(f"{self} only contains one item")
16551658
return self.values
16561659

1657-
def should_store(self, value: ArrayLike) -> bool:
1658-
"""
1659-
Can we set the given array-like value inplace?
1660-
"""
1661-
return isinstance(value, self._holder)
1662-
16631660
def set(self, locs, values):
16641661
assert locs.tolist() == [0]
16651662
self.values = values
@@ -2050,9 +2047,6 @@ def _can_hold_element(self, element: Any) -> bool:
20502047
element, (float, int, complex, np.float_, np.int_)
20512048
) and not isinstance(element, (bool, np.bool_))
20522049

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

20572051
class IntBlock(NumericBlock):
20582052
__slots__ = ()
@@ -2218,7 +2212,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
22182212
_can_hold_element = DatetimeBlock._can_hold_element
22192213
to_native_types = DatetimeBlock.to_native_types
22202214
fill_value = np.datetime64("NaT", "ns")
2221-
should_store = Block.should_store
22222215
array_values = ExtensionBlock.array_values
22232216

22242217
@property
@@ -2680,20 +2673,6 @@ def _replace_coerce(
26802673

26812674
class CategoricalBlock(ExtensionBlock):
26822675
__slots__ = ()
2683-
is_categorical = True
2684-
_can_hold_na = True
2685-
2686-
should_store = Block.should_store
2687-
2688-
def __init__(self, values, placement, ndim=None):
2689-
# coerce to categorical if we can
2690-
values = extract_array(values)
2691-
assert isinstance(values, Categorical), type(values)
2692-
super().__init__(values, placement=placement, ndim=ndim)
2693-
2694-
@property
2695-
def _holder(self):
2696-
return Categorical
26972676

26982677
def replace(
26992678
self,

0 commit comments

Comments
 (0)