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
22 changes: 7 additions & 15 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,25 +1515,14 @@ class SingleBlockManager(BlockManager):
def __init__(
self,
block: Block,
axis: Union[Index, List[Index]],
axis: Index,
do_integrity_check: bool = False,
fastpath: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastpath has no effect anymore, now? It is still being used in places internally?

):
assert isinstance(block, Block), type(block)
assert isinstance(axis, Index), type(axis)

if isinstance(axis, list):
if len(axis) != 1:
raise ValueError(
"cannot create SingleBlockManager with more than 1 axis"
)
axis = axis[0]

# passed from constructor, single block, single axis
if fastpath:
self.axes = [axis]
else:
self.axes = [ensure_index(axis)]

self.axes = [axis]
self.blocks = tuple([block])

@classmethod
Expand Down Expand Up @@ -1633,7 +1622,9 @@ def fast_xs(self, loc):
"""
raise NotImplementedError("Use series._values[loc] instead")

def concat(self, to_concat, new_axis: Index) -> "SingleBlockManager":
def concat(
self, to_concat: List["SingleBlockManager"], new_axis: Index
) -> "SingleBlockManager":
"""
Concatenate a list of SingleBlockManagers into a single
SingleBlockManager.
Expand All @@ -1649,6 +1640,7 @@ def concat(self, to_concat, new_axis: Index) -> "SingleBlockManager":
-------
SingleBlockManager
"""
assert isinstance(new_axis, Index), new_axis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already asserted in the SingleBlockManager constructor, so is not needed here?

non_empties = [x for x in to_concat if len(x) > 0]

# check if all series are of the same block type:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def get_result(self):
name = com.consensus_name_attr(self.objs)

mgr = self.objs[0]._data.concat(
[x._data for x in self.objs], self.new_axes
[x._data for x in self.objs], self.new_axes[0]
)
cons = self.objs[0]._constructor
return cons(mgr, name=name).__finalize__(self, method="concat")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def create_single_mgr(typestr, num_rows=None):

return SingleBlockManager(
create_block(typestr, placement=slice(0, num_rows), item_shape=()),
np.arange(num_rows),
Index(np.arange(num_rows)),
)


Expand Down