Skip to content

Commit c9182df

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Remove never-True Block.is_sparse (#27037)
1 parent f558763 commit c9182df

File tree

4 files changed

+18
-43
lines changed

4 files changed

+18
-43
lines changed

pandas/core/dtypes/concat.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ def _get_series_result_type(result, objs=None):
7373
return DataFrame
7474

7575
# otherwise it is a SingleBlockManager (axis = 0)
76-
if result._block.is_sparse:
77-
return SparseSeries
78-
else:
79-
return objs[0]._constructor
76+
return objs[0]._constructor
8077

8178

8279
def _get_frame_result_type(result, objs):

pandas/core/internals/blocks.py

+10-24
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ class Block(PandasObject):
6262
is_bool = False
6363
is_object = False
6464
is_categorical = False
65-
is_sparse = False
6665
is_extension = False
67-
_box_to_block_values = True
6866
_can_hold_na = False
6967
_can_consolidate = True
7068
_verify_integrity = True
@@ -182,10 +180,6 @@ def get_values(self, dtype=None):
182180
def to_dense(self):
183181
return self.values.view()
184182

185-
@property
186-
def _na_value(self):
187-
return np.nan
188-
189183
@property
190184
def fill_value(self):
191185
return np.nan
@@ -1189,8 +1183,6 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
11891183
# sparse is treated like an ndarray, but needs .get_values() shaping
11901184

11911185
values = self.values
1192-
if self.is_sparse:
1193-
values = self.get_values()
11941186

11951187
if fill_tuple is None:
11961188
fill_value = self.fill_value
@@ -1411,6 +1403,9 @@ def quantile(self, qs, interpolation='linear', axis=0):
14111403
-------
14121404
Block
14131405
"""
1406+
# We should always have ndim == 2 becase Series dispatches to DataFrame
1407+
assert self.ndim == 2
1408+
14141409
if self.is_datetimetz:
14151410
# TODO: cleanup this special case.
14161411
# We need to operate on i8 values for datetimetz
@@ -1420,8 +1415,7 @@ def quantile(self, qs, interpolation='linear', axis=0):
14201415

14211416
# TODO: NonConsolidatableMixin shape
14221417
# Usual shape inconsistencies for ExtensionBlocks
1423-
if self.ndim > 1:
1424-
values = values[None, :]
1418+
values = values[None, :]
14251419
else:
14261420
values = self.get_values()
14271421
values, _ = self._try_coerce_args(values, values)
@@ -1433,14 +1427,11 @@ def quantile(self, qs, interpolation='linear', axis=0):
14331427
qs = [qs]
14341428

14351429
if is_empty:
1436-
if self.ndim == 1:
1437-
result = self._na_value
1438-
else:
1439-
# create the array of na_values
1440-
# 2d len(values) * len(qs)
1441-
result = np.repeat(np.array([self.fill_value] * len(qs)),
1442-
len(values)).reshape(len(values),
1443-
len(qs))
1430+
# create the array of na_values
1431+
# 2d len(values) * len(qs)
1432+
result = np.repeat(np.array([self.fill_value] * len(qs)),
1433+
len(values)).reshape(len(values),
1434+
len(qs))
14441435
else:
14451436
# asarray needed for Sparse, see GH#24600
14461437
# TODO: Why self.values and not values?
@@ -1451,8 +1442,7 @@ def quantile(self, qs, interpolation='linear', axis=0):
14511442
interpolation=interpolation)
14521443

14531444
result = np.array(result, copy=False)
1454-
if self.ndim > 1:
1455-
result = result.T
1445+
result = result.T
14561446

14571447
if orig_scalar and not lib.is_scalar(result):
14581448
# result could be scalar in case with is_empty and self.ndim == 1
@@ -2024,10 +2014,6 @@ class DatetimeLikeBlockMixin:
20242014
def _holder(self):
20252015
return DatetimeArray
20262016

2027-
@property
2028-
def _na_value(self):
2029-
return tslibs.NaT
2030-
20312017
@property
20322018
def fill_value(self):
20332019
return tslibs.iNaT

pandas/core/internals/concat.py

-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
187187
pass
188188
elif getattr(self.block, 'is_categorical', False):
189189
pass
190-
elif getattr(self.block, 'is_sparse', False):
191-
pass
192190
elif getattr(self.block, 'is_extension', False):
193191
pass
194192
else:

pandas/core/internals/managers.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,11 @@ def __init__(self,
102102
self.blocks = tuple(blocks) # type: Tuple[Block, ...]
103103

104104
for block in blocks:
105-
if block.is_sparse:
106-
if len(block.mgr_locs) != 1:
107-
raise AssertionError("Sparse block refers to multiple "
108-
"items")
109-
else:
110-
if self.ndim != block.ndim:
111-
raise AssertionError(
112-
'Number of Block dimensions ({block}) must equal '
113-
'number of axes ({self})'.format(block=block.ndim,
114-
self=self.ndim))
105+
if self.ndim != block.ndim:
106+
raise AssertionError(
107+
'Number of Block dimensions ({block}) must equal '
108+
'number of axes ({self})'.format(block=block.ndim,
109+
self=self.ndim))
115110

116111
if do_integrity_check:
117112
self._verify_integrity()
@@ -966,7 +961,7 @@ def iget(self, i, fastpath=True):
966961
"""
967962
block = self.blocks[self._blknos[i]]
968963
values = block.iget(self._blklocs[i])
969-
if not fastpath or not block._box_to_block_values or values.ndim != 1:
964+
if not fastpath or values.ndim != 1:
970965
return values
971966

972967
# fastpath shortcut for select a single-dim from a 2-dim BM
@@ -1820,8 +1815,7 @@ def _shape_compat(x):
18201815

18211816

18221817
def _interleaved_dtype(
1823-
blocks: List[Block]
1824-
) -> Optional[Union[np.dtype, ExtensionDtype]]:
1818+
blocks: List[Block]) -> Optional[Union[np.dtype, ExtensionDtype]]:
18251819
"""Find the common dtype for `blocks`.
18261820
18271821
Parameters

0 commit comments

Comments
 (0)