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

CoW: Fix deprecation warning for chained assignment #56166

Merged
merged 6 commits into from
Nov 27, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 25, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

I hate the SettingWithCopyWarning mechanism...

2 cases were fixed here:

  • the parent that holds the item_cache might be dead, e.g. the ref count is not increased. We have to check this when looking at the cacher
  • iloc does not populate the item_cache but it sets _cacher on the new object, so we have to check if we are actually part of the item_cache

xref #56019

@phofl phofl added this to the 2.2 milestone Nov 25, 2023
@phofl phofl changed the title CoW: Fix deprecation warning for chained assignment CoW: Fix deprecation warning for chained assignment in put mask Nov 25, 2023
@phofl phofl changed the title CoW: Fix deprecation warning for chained assignment in put mask CoW: Fix deprecation warning for chained assignment Nov 25, 2023
@mroeschke mroeschke added Warnings Warnings that appear or should be added to pandas Copy / view semantics labels Nov 26, 2023
@jorisvandenbossche
Copy link
Member

I hate the SettingWithCopyWarning mechanism...

Oh I am looking forward to ripping out all that code ;)

@phofl
Copy link
Member Author

phofl commented Nov 27, 2023

Yes me too, I call dips on doing that :)

def test_methods_iloc_getitem_item_cache(func, args, using_copy_on_write):
df = DataFrame({"a": [1, 2, 3], "b": 1})
ser = df.iloc[:, 0]
getattr(ser, func)(*args, inplace=True)
Copy link
Member

Choose a reason for hiding this comment

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

This should raise a warning?

Copy link
Member

Choose a reason for hiding this comment

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

(or is that something we haven't implemented yet)

Copy link
Member Author

Choose a reason for hiding this comment

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

That should raise but we haven’t done that yet I think, but it shouldn’t raise a chained assignment warning, which is what happens on main right now

the implementation will look similar to #56168

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Thanks a lot!
Merging this so I can use it in my chained assignment PR

@jorisvandenbossche jorisvandenbossche merged commit aa994bb into pandas-dev:main Nov 27, 2023
10 of 37 checks passed
@phofl phofl deleted the fix_cow_warning branch November 27, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Copy / view semantics Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants