Skip to content

TYP: enforce tighter inputs on SingleBlockManager #33092

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
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update per comments
  • Loading branch information
jbrockmendel committed Mar 28, 2020
commit b241365e677839b90a9ed67bfcaa744a1fdba5bc
18 changes: 5 additions & 13 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,7 @@ def get_axe(block, qs, axes):
values = values.take(indexer)

return SingleBlockManager(
make_block(values, ndim=1, placement=np.arange(len(values))),
axes[0],
fastpath=True,
make_block(values, ndim=1, placement=np.arange(len(values))), axes[0],
)

def isna(self, func) -> "BlockManager":
Expand Down Expand Up @@ -1007,7 +1005,6 @@ def iget(self, i: int) -> "SingleBlockManager":
values, placement=slice(0, len(values)), ndim=1
),
self.axes[1],
fastpath=True,
)

def delete(self, item):
Expand Down Expand Up @@ -1513,11 +1510,7 @@ class SingleBlockManager(BlockManager):
__slots__ = ()

def __init__(
self,
block: Block,
axis: Index,
do_integrity_check: bool = False,
fastpath: bool = False,
self, block: Block, axis: Index, do_integrity_check: bool = False,
):
assert isinstance(block, Block), type(block)
assert isinstance(axis, Index), type(axis)
Expand All @@ -1534,15 +1527,15 @@ def from_blocks(
"""
assert len(blocks) == 1
assert len(axes) == 1
return cls(blocks[0], axes[0], do_integrity_check=False, fastpath=True)
return cls(blocks[0], axes[0], do_integrity_check=False)

@classmethod
def from_array(cls, array: ArrayLike, index: Index) -> "SingleBlockManager":
"""
Constructor for if we have an array that is not yet a Block.
"""
block = make_block(array, placement=slice(0, len(index)), ndim=1)
return cls(block, index, fastpath=True)
return cls(block, index)

def _post_setstate(self):
pass
Expand All @@ -1568,7 +1561,7 @@ def get_slice(self, slobj: slice, axis: int = 0) -> "SingleBlockManager":
blk = self._block
array = blk._slice(slobj)
block = blk.make_block_same_class(array, placement=range(len(array)))
return type(self)(block, self.index[slobj], fastpath=True)
return type(self)(block, self.index[slobj])

@property
def index(self) -> Index:
Expand Down Expand Up @@ -1640,7 +1633,6 @@ def concat(
-------
SingleBlockManager
"""
assert isinstance(new_axis, Index), new_axis
non_empties = [x for x in to_concat if len(x) > 0]

# check if all series are of the same block type:
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,7 @@ def _get_values_tuple(self, key):

def _get_values(self, indexer):
try:
return self._constructor(
self._data.get_slice(indexer), fastpath=True
).__finalize__(self)
return self._constructor(self._data.get_slice(indexer)).__finalize__(self)
except ValueError:
# mpl compat if we look up e.g. ser[:, np.newaxis];
# see tests.series.timeseries.test_mpl_compat_hack
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_external_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_concat_series():
values = np.arange(3, dtype="int64")
block = CustomBlock(values, placement=slice(0, 3))
mgr = SingleBlockManager(block, pd.RangeIndex(3))
s = pd.Series(mgr, pd.RangeIndex(3), fastpath=True)
s = pd.Series(mgr, pd.RangeIndex(3))

res = pd.concat([s, s])
assert isinstance(res._data.blocks[0], CustomBlock)
Expand Down