Skip to content

Commit 9c26a2b

Browse files
jorisvandenbosschejbrockmendel
authored andcommitted
PERF: skip non-consolidatable blocks when checking consolidation (pandas-dev#32826)
1 parent 1366dbf commit 9c26a2b

File tree

3 files changed

+2
-16
lines changed

3 files changed

+2
-16
lines changed

pandas/core/arrays/sparse/array.py

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
268268
Indices: array([2, 3], dtype=int32)
269269
"""
270270

271-
_pandas_ftype = "sparse"
272271
_subtyp = "sparse_array" # register ABCSparseArray
273272
_deprecations = PandasObject._deprecations | frozenset(["get_values"])
274273
_sparse_index: SparseIndex

pandas/core/internals/blocks.py

-13
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class Block(PandasObject):
110110
_can_consolidate = True
111111
_verify_integrity = True
112112
_validate_ndim = True
113-
_ftype = "dense"
114113
_concatenator = staticmethod(np.concatenate)
115114

116115
def __init__(self, values, placement, ndim=None):
@@ -322,14 +321,6 @@ def shape(self):
322321
def dtype(self):
323322
return self.values.dtype
324323

325-
@property
326-
def ftype(self) -> str:
327-
if getattr(self.values, "_pandas_ftype", False):
328-
dtype = self.dtype.subtype
329-
else:
330-
dtype = self.dtype
331-
return f"{dtype}:{self._ftype}"
332-
333324
def merge(self, other):
334325
return _merge_blocks([self, other])
335326

@@ -1956,10 +1947,6 @@ def where(
19561947

19571948
return [self.make_block_same_class(result, placement=self.mgr_locs)]
19581949

1959-
@property
1960-
def _ftype(self):
1961-
return getattr(self.values, "_pandas_ftype", Block._ftype)
1962-
19631950
def _unstack(self, unstacker_func, new_columns, n_rows, fill_value):
19641951
# ExtensionArray-safe unstack.
19651952
# We override ObjectBlock._unstack, which unstacks directly on the

pandas/core/internals/managers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ def is_consolidated(self) -> bool:
676676
return self._is_consolidated
677677

678678
def _consolidate_check(self) -> None:
679-
ftypes = [blk.ftype for blk in self.blocks]
680-
self._is_consolidated = len(ftypes) == len(set(ftypes))
679+
dtypes = [blk.dtype for blk in self.blocks if blk._can_consolidate]
680+
self._is_consolidated = len(dtypes) == len(set(dtypes))
681681
self._known_consolidated = True
682682

683683
@property

0 commit comments

Comments
 (0)