UpSetPlot icon indicating copy to clipboard operation
UpSetPlot copied to clipboard

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

Open ch-sander opened this issue 9 months ago • 1 comments

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)

ch-sander avatar Mar 16 '25 12:03 ch-sander

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")

ch-sander avatar Mar 16 '25 12:03 ch-sander