Skip to content
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

REF: BlockManager.delete -> idelete #33332

Merged
merged 5 commits into from
Apr 6, 2020
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
3 changes: 2 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3713,7 +3713,8 @@ def __delitem__(self, key) -> None:
# If the above loop ran and didn't delete anything because
# there was no match, this call should raise the appropriate
# exception:
self._mgr.delete(key)
loc = self.axes[-1].get_loc(key)
self._mgr.idelete(loc)

# delete from the caches
try:
Expand Down
15 changes: 6 additions & 9 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,10 @@ def iget(self, i: int) -> "SingleBlockManager":
self.axes[1],
)

def delete(self, item):
def idelete(self, indexer):
Copy link
Contributor

Choose a reason for hiding this comment

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

this should just be typed as int i think (followon ok)

"""
Delete selected item (items if non-unique) in-place.
Delete selected locations in-place (new block and array, same BlockManager)
"""
indexer = self.items.get_loc(item)

is_deleted = np.zeros(self.shape[0], dtype=np.bool_)
is_deleted[indexer] = True
ref_loc_offset = -is_deleted.cumsum()
Expand Down Expand Up @@ -1606,15 +1604,14 @@ def _consolidate_check(self):
def _consolidate_inplace(self):
pass

def delete(self, item):
def idelete(self, indexer):
"""
Delete single item from SingleBlockManager.
Delete single location from SingleBlockManager.

Ensures that self.blocks doesn't become empty.
"""
loc = self.items.get_loc(item)
self._block.delete(loc)
self.axes[0] = self.axes[0].delete(loc)
self._block.delete(indexer)
self.axes[0] = self.axes[0].delete(indexer)

def fast_xs(self, loc):
"""
Expand Down