-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: Split blocks in blk.delete #50148
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
Changes from 7 commits
e8c3a52
a11da75
09f6adb
e54adfa
baa76c8
3d9e447
3f07f6d
b519fee
cf4a2d8
d573c35
30f8cd3
bf6d9cc
bc0ec83
165ccca
52e3514
4df1320
c5b5061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1314,7 +1314,7 @@ def quantile( | |
# --------------------------------------------------------------------- | ||
# Abstract Methods Overridden By EABackedBlock and NumpyBlock | ||
|
||
def delete(self, loc) -> Block: | ||
def delete(self, loc) -> list[Block]: | ||
""" | ||
Return a new Block with the given loc(s) deleted. | ||
""" | ||
|
@@ -1531,11 +1531,11 @@ def putmask(self, mask, new) -> list[Block]: | |
|
||
return [self] | ||
|
||
def delete(self, loc) -> Block: | ||
def delete(self, loc) -> list[Block]: | ||
# This will be unnecessary if/when __array_function__ is implemented | ||
values = self.values.delete(loc) | ||
mgr_locs = self._mgr_locs.delete(loc) | ||
return type(self)(values, placement=mgr_locs, ndim=self.ndim) | ||
return [type(self)(values, placement=mgr_locs, ndim=self.ndim)] | ||
|
||
@cache_readonly | ||
def array_values(self) -> ExtensionArray: | ||
|
@@ -1850,10 +1850,39 @@ def get_values(self, dtype: DtypeObj | None = None) -> np.ndarray: | |
def values_for_json(self) -> np.ndarray: | ||
return self.values | ||
|
||
def delete(self, loc) -> Block: | ||
values = np.delete(self.values, loc, 0) | ||
mgr_locs = self._mgr_locs.delete(loc) | ||
return type(self)(values, placement=mgr_locs, ndim=self.ndim) | ||
def delete(self, loc) -> list[Block]: | ||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not is_list_like(loc): | ||
loc = [loc] | ||
|
||
if self.ndim == 1: | ||
values = np.delete(self.values, loc) | ||
mgr_locs = self._mgr_locs.delete(loc) | ||
return [type(self)(values, placement=mgr_locs, ndim=self.ndim)] | ||
|
||
if np.max(loc) >= self.values.shape[0]: | ||
raise IndexError | ||
|
||
# Add one out-of-bounds indexer as maximum to collect | ||
# all columns after our last indexer if any | ||
loc = np.concatenate([loc, [self.values.shape[0]]]) | ||
mgr_locs_arr = self._mgr_locs.as_array | ||
new_blocks: list[Block] = [] | ||
|
||
previous_loc = -1 | ||
for idx in loc: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this reminds me of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, this seemed to do something different than what we need. Tried to get it to work a while back, but didn't get it to work |
||
|
||
if idx == previous_loc + 1: | ||
# There is now column between current and last idx | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pass | ||
else: | ||
values = self.values[previous_loc + 1 : idx, :] | ||
locs = mgr_locs_arr[previous_loc + 1 : idx] | ||
nb = type(self)(values, placement=BlockPlacement(locs), ndim=self.ndim) | ||
new_blocks.append(nb) | ||
|
||
previous_loc = idx | ||
|
||
return new_blocks | ||
|
||
|
||
class NumericBlock(NumpyBlock): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for 2D EAs we probably want to do the same thing as we do for NumpyBlock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any 2D EAs? I agree in general, but thought all of them were 1D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see NDArrayBackedExtensionBlock