Skip to content

Conversation

chilin0525
Copy link
Contributor

@chilin0525 chilin0525 commented Feb 16, 2025

@chilin0525
Copy link
Contributor Author

Since there has been no feedback for two weeks, just a friendly ping @mroeschke @rhshadrach @WillAyd , thanks 🙏

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Comment on lines 1470 to 1474
# Check that view is modified correctly
expected_view = DataFrame(
{"B": [2, 2, 2, 2], "C": [3, 2, 1, 2]}, index=df.index
)
tm.assert_frame_equal(df, expected_view)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Once the assignment is done, this is no longer a view. Can you change to just "df" instead of "view".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sovled in fcffbf2

updated to work correctly with NumPy >= 2 (:issue:`57739`)
- :meth:`Series.str.decode` result now has ``StringDtype`` when ``future.infer_string`` is True (:issue:`60709`)
- :meth:`~Series.to_hdf` and :meth:`~DataFrame.to_hdf` now round-trip with ``StringDtype`` (:issue:`60663`)
- The :meth:`DataFrame.iloc` now works correctly with ``copy_on_write`` option (:issue:`60309`)
Copy link
Member

Choose a reason for hiding this comment

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

Can you give a little more detail here. Perhaps adding

after subsetting the columns of a DataFrame and using a slice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, Solved in 725b41b

Comment on lines 576 to 580
if isinstance(indexer[1], slice) and indexer[1] == slice(None):
col_indexer = slice(None)
else:
col_indexer = np.arange(len(blk_loc))
self.blocks[0].setitem((indexer[0], col_indexer), value)
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me why it's correct to pass through slice(None) but not other cases, e.g. slice(0, 3, 2) or [0, 1].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. My current changes failed under the following test case. I'll mark the PR as a draft until I properly handle the bug and will also add more test cases. Thanks!

dftest3 = pd.DataFrame(
    {"A": [1, 4, 1, 5], "B": [2, 5, 2, 6], "C": [3, 6, 1, 7], "D": [8, 9, 10, 11]}
)
df3 = dftest3[["B", "C", "D"]]
df3.iloc[[1, 3], 0:3:2] = [[2, 2], [2, 2]]

@chilin0525 chilin0525 marked this pull request as draft March 2, 2025 08:46
Copy link
Contributor

github-actions bot commented Apr 2, 2025

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Apr 2, 2025
@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Apr 2, 2025
@jorisvandenbossche jorisvandenbossche marked this pull request as ready for review September 12, 2025 14:37
@jorisvandenbossche
Copy link
Member

@chilin0525 I wanted to fix this bug and decided to start from this PR to reuse the test and whatsnew, so pushed some changes here

@jorisvandenbossche jorisvandenbossche added Bug Indexing Related to indexing on series/frames, not to indexes themselves and removed Stale labels Sep 12, 2025
@jorisvandenbossche jorisvandenbossche added this to the 2.3.3 milestone Sep 12, 2025
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Sep 21, 2025

This special case of splitting the block (to avoid having the copy the entire block) when a copy for CoW was triggered was clearly not covered very well. After expanding the test coverage (and updating some existing setitem tests to be parametrized on having a reference or not), had to do some more fixes. So this turned out to be more complicated than anticipated ..

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

lgtm

@rhshadrach rhshadrach merged commit e79f156 into pandas-dev:main Sep 22, 2025
47 checks passed
Copy link

lumberbot-app bot commented Sep 22, 2025

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.3.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 e79f1565e6e8598a9381db44b8d284d1e11dff2e
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #60941: BUG: Fixed assign failure when with Copy-on-Write'
  1. Push to a named branch:
git push YOURFORK 2.3.x:auto-backport-of-pr-60941-on-2.3.x
  1. Create a PR against branch 2.3.x, I would have named this PR:

"Backport PR #60941 on branch 2.3.x (BUG: Fixed assign failure when with Copy-on-Write)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@rhshadrach
Copy link
Member

Thanks @chilin0525 and @jorisvandenbossche

@jorisvandenbossche
Copy link
Member

Manual backport -> #62409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Copy / view semantics Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: assignment fails with copy_on_write = True
4 participants