Skip to content

CLN: Remove never-True Block.is_sparse #27037

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 5 commits into from
Jun 25, 2019
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
5 changes: 1 addition & 4 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def _get_series_result_type(result, objs=None):
return DataFrame

# otherwise it is a SingleBlockManager (axis = 0)
if result._block.is_sparse:
return SparseSeries
else:
return objs[0]._constructor
return objs[0]._constructor


def _get_frame_result_type(result, objs):
Expand Down
34 changes: 10 additions & 24 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class Block(PandasObject):
is_bool = False
is_object = False
is_categorical = False
is_sparse = False
is_extension = False
_box_to_block_values = True
_can_hold_na = False
_can_consolidate = True
_verify_integrity = True
Expand Down Expand Up @@ -182,10 +180,6 @@ def get_values(self, dtype=None):
def to_dense(self):
return self.values.view()

@property
def _na_value(self):
return np.nan

@property
def fill_value(self):
return np.nan
Expand Down Expand Up @@ -1189,8 +1183,6 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
# sparse is treated like an ndarray, but needs .get_values() shaping

values = self.values
if self.is_sparse:
values = self.get_values()

if fill_tuple is None:
fill_value = self.fill_value
Expand Down Expand Up @@ -1411,6 +1403,9 @@ def quantile(self, qs, interpolation='linear', axis=0):
-------
Block
"""
# We should always have ndim == 2 becase Series dispatches to DataFrame
assert self.ndim == 2

if self.is_datetimetz:
# TODO: cleanup this special case.
# We need to operate on i8 values for datetimetz
Expand All @@ -1420,8 +1415,7 @@ def quantile(self, qs, interpolation='linear', axis=0):

# TODO: NonConsolidatableMixin shape
# Usual shape inconsistencies for ExtensionBlocks
if self.ndim > 1:
values = values[None, :]
values = values[None, :]
else:
values = self.get_values()
values, _ = self._try_coerce_args(values, values)
Expand All @@ -1433,14 +1427,11 @@ def quantile(self, qs, interpolation='linear', axis=0):
qs = [qs]

if is_empty:
if self.ndim == 1:
result = self._na_value
else:
# create the array of na_values
# 2d len(values) * len(qs)
result = np.repeat(np.array([self.fill_value] * len(qs)),
len(values)).reshape(len(values),
len(qs))
# create the array of na_values
# 2d len(values) * len(qs)
result = np.repeat(np.array([self.fill_value] * len(qs)),
len(values)).reshape(len(values),
len(qs))
else:
# asarray needed for Sparse, see GH#24600
# TODO: Why self.values and not values?
Expand All @@ -1451,8 +1442,7 @@ def quantile(self, qs, interpolation='linear', axis=0):
interpolation=interpolation)

result = np.array(result, copy=False)
if self.ndim > 1:
result = result.T
result = result.T

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

@property
def _na_value(self):
return tslibs.NaT

@property
def fill_value(self):
return tslibs.iNaT
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ def get_reindexed_values(self, empty_dtype, upcasted_na):
pass
elif getattr(self.block, 'is_categorical', False):
pass
elif getattr(self.block, 'is_sparse', False):
pass
elif getattr(self.block, 'is_extension', False):
pass
else:
Expand Down
20 changes: 7 additions & 13 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,11 @@ def __init__(self,
self.blocks = tuple(blocks) # type: Tuple[Block, ...]

for block in blocks:
if block.is_sparse:
if len(block.mgr_locs) != 1:
raise AssertionError("Sparse block refers to multiple "
"items")
else:
if self.ndim != block.ndim:
raise AssertionError(
'Number of Block dimensions ({block}) must equal '
'number of axes ({self})'.format(block=block.ndim,
self=self.ndim))
if self.ndim != block.ndim:
raise AssertionError(
'Number of Block dimensions ({block}) must equal '
'number of axes ({self})'.format(block=block.ndim,
self=self.ndim))

if do_integrity_check:
self._verify_integrity()
Expand Down Expand Up @@ -966,7 +961,7 @@ def iget(self, i, fastpath=True):
"""
block = self.blocks[self._blknos[i]]
values = block.iget(self._blklocs[i])
if not fastpath or not block._box_to_block_values or values.ndim != 1:
if not fastpath or values.ndim != 1:
return values

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


def _interleaved_dtype(
blocks: List[Block]
) -> Optional[Union[np.dtype, ExtensionDtype]]:
blocks: List[Block]) -> Optional[Union[np.dtype, ExtensionDtype]]:
"""Find the common dtype for `blocks`.

Parameters
Expand Down