-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: Avoid copying whole block for single block case #51435
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 all commits
13f4550
f9de331
1fbf990
1daf762
b27b36d
1a61c80
f13f699
109c477
91324d5
c8d0839
c03f140
bf13790
0bc41fd
2a4bbf5
f659911
64e0e7b
4798ca6
08edc6f
10340ba
e287ae1
094493e
db63316
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 |
---|---|---|
|
@@ -371,8 +371,30 @@ def setitem(self, indexer, value) -> Self: | |
raise ValueError(f"Cannot set values with ndim > {self.ndim}") | ||
|
||
if using_copy_on_write() and not self._has_no_reference(0): | ||
# if being referenced -> perform Copy-on-Write and clear the reference | ||
# this method is only called if there is a single block -> hardcoded 0 | ||
# Split blocks to only copy the columns we want to modify | ||
if self.ndim == 2 and isinstance(indexer, tuple): | ||
blk_loc = self.blklocs[indexer[1]] | ||
if is_list_like(blk_loc) and blk_loc.ndim == 2: | ||
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. how would you get blk_loc.ndim == 2? 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. Would have to check, got test failures without checking this 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. Did you check this again? 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. Forget to comment 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. What indexer[1] causes this? this strikes me as very weird 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. test_loc_setitem_reordering_with_all_true_indexer That's one of the test that hits this if you want to take a look 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. i added this check and a breakpoint on main and it didnt get hit in that test (or that test file). are there other changes in this PR that cause it to be reached? |
||
blk_loc = np.squeeze(blk_loc, axis=0) | ||
elif not is_list_like(blk_loc): | ||
# Keep dimension and copy data later | ||
blk_loc = [blk_loc] # type: ignore[assignment] | ||
if len(blk_loc) == 0: | ||
return self.copy(deep=False) | ||
|
||
values = self.blocks[0].values | ||
if values.ndim == 2: | ||
values = values[blk_loc] | ||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# "T" has no attribute "_iset_split_block" | ||
self._iset_split_block( # type: ignore[attr-defined] | ||
0, blk_loc, values | ||
) | ||
# first block equals values | ||
self.blocks[0].setitem((indexer[0], np.arange(len(blk_loc))), value) | ||
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.
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. I like this, thx 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. It looks like this has side effects. Rolling back for now |
||
return self | ||
# No need to split if we either set all columns or on a single block | ||
# manager | ||
self = self.copy() | ||
|
||
return self.apply("setitem", indexer=indexer, value=value) | ||
|
Uh oh!
There was an error while loading. Please reload this page.