-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Description
When using upsetplot version 0.9.0 with Pandas 3.0.0 and Matplotlib 3.10.8, the library fails during the plotting phase.
Pandas 3.0 has fully enabled Copy-on-Write (CoW) by default, and it can no longer be disabled via options (attempting to set pd.options.mode.copy_on_write = False now throws a Pandas4Warning). This causes internal styling assignments in upsetplot/plotting.py that use inplace=True on DataFrame slices to fail. Consequently, style attributes like facecolor and edgecolor remain NaN, causing Matplotlib to crash with a ValueError.
Environment
upsetplot version: 0.9.0
pandas version: 3.0.0
matplotlib version: 3.10.8
Steps to Reproduce
Running a standard UpSet plot in an environment with Pandas 3.0.0+ results in a crash because the internal styles dataframe is not updated correctly.
from upsetplot import UpSet, from_memberships
import matplotlib.pyplot as plt
import pandas as pd
# Pandas 3.0.0+ enforces Copy-on-Write
data = from_memberships([[0, 1], [1, 2]], data=[5, 10])
upset = UpSet(data)
upset.plot()
Traceback
Python
# Warning encountered when attempting workaround:
Pandas4Warning: The 'mode.copy_on_write' option is deprecated. Copy-on-Write can no longer be disabled (it is always enabled with pandas >= 3.0), and setting the option has no impact.
# The primary library error:
.../upsetplot/plotting.py:795: ChainedAssignmentError: A value is being set on a copy of a DataFrame or Series through chained assignment using an inplace method.
Such inplace method never works to update the original DataFrame or Series...
styles["linewidth"].fillna(1, inplace=True)
---------------------------------------------------------------------------
ValueError: Invalid RGBA argument: nan
File .../upsetplot/plotting.py:1098, in UpSet.plot(self, fig)
-> 1098 self.plot_matrix(matrix_ax)
File .../upsetplot/plotting.py:810, in UpSet.plot_matrix(self, ax)
--> 810 ax.scatter(
811 *self._swapaxes(x, y),
812 **styles.rename(columns=style_columns),
813 )
File .../matplotlib/colors.py:401, in _to_rgba_no_colorcycle(c, alpha)
--> 401 raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
ValueError: Invalid RGBA argument: nan
Actual Behavior
In upsetplot/plotting.py, lines 795–798 attempt to fill missing style values:
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)
Under Pandas 3.0.0 CoW rules, these inplace=True operations on a slice fail to update the styles dataframe. Matplotlib 3.10.8 then receives NaN values for colors/widths and raises a ValueError.
Thanks a lot for your help and for developing this package