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

pandas FutureWarning resulting from chained assignment #281

Open
verheytb opened this issue Jul 23, 2024 · 1 comment
Open

pandas FutureWarning resulting from chained assignment #281

verheytb opened this issue Jul 23, 2024 · 1 comment

Comments

@verheytb
Copy link

Hello, I'm getting this error when working with the upsetplot package.

C:\Users\<username>\miniconda3\Lib\site-packages\upsetplot\plotting.py:795: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.


  styles["linewidth"].fillna(1, inplace=True)
@AnthonyTedde
Copy link

Hi everyone,

I'm also encountering the following warnings when using upsetplot:

/opt/conda/lib/python3.10/site-packages/upsetplot/plotting.py:795: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

  styles["linewidth"].fillna(1, inplace=True)
/opt/conda/lib/python3.10/site-packages/upsetplot/plotting.py:796: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
...

This warning suggests that the current use of .fillna(..., inplace=True) modifies a copy rather than the original DataFrame or Series. With upcoming changes in pandas 3.0, this approach will no longer work.

Would it be possible to update the code to avoid chained assignment? The suggested approach would be to replace:

styles["linewidth"].fillna(1, inplace=True)

With:

styles["linewidth"] = styles["linewidth"].fillna(1)

This change should ensure compatibility with future versions of pandas and prevent the warning from appearing.

Thanks in advance for your attention to this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants