8000 FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. · Issue #292 · jnothman/UpSetPlot · GitHub
[go: up one dir, main page]

Skip to content

FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. #292

Open

Description

@ch-sander

I get this warning which might require an update in the package

/usr/local/lib/python3.11/dist-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)
/usr/local/lib/python3.11/dist-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.
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["facecolor"].fillna(self._facecolor, inplace=True)
/usr/local/lib/python3.11/dist-packages/upsetplot/plotting.py:797: 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["edgecolor"].fillna(styles["facecolor"], inplace=True)
/usr/local/lib/python3.11/dist-packages/upsetplot/plotting.py:798: 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["linestyle"].fillna("solid", inplace=True)

Activity

  1. ch-sander commented on Mar 16, 2025

    @ch-sander
    Author

    https://github.com/jnothman/UpSetPlot/blob/dcfadae04edfffe321fc0b002bf1865019f75f9b/upsetplot/plotting.py#L782C1-L798C58

    change

            styles = (
                pd.DataFrame(styles)
                .reindex(columns=style_columns.keys())
                .astype(
                    {
                        "facecolor": "O",
                        "edgecolor": "O",
                        "linewidth": float,
                        "linestyle": "O",
                        "hatch": "O",
                    }
                )
            )
            styles["linewidth"].fillna(1, inplace=True)
            styles["facecolor"].fillna(self._facecolor, inplace=True)
            styles["edgecolor"].fillna(styles["facecolor"], inplace=True)
            styles["linestyle"].fillna("solid", inplace=True)

    to

    styles = (
        pd.DataFrame(styles)
        .reindex(columns=style_columns.keys())
        .astype(
            {
                "facecolor": "O",
                "edgecolor": "O",
                "linewidth": float,
                "linestyle": "O",
                "hatch": "O",
            }
        )
    )
    
    styles["linewidth"] = styles["linewidth"].fillna(1)
    styles["facecolor"] = styles["facecolor"].fillna(self._facecolor)
    styles["edgecolor"] = styles["edgecolor"].fillna(styles["facecolor"])
    styles["linestyle"] = styles["linestyle"].fillna("solid")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0