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

Not compatible with pandas copy on write #276

Open
rmnldwg opened this issue Apr 4, 2024 · 0 comments
Open

Not compatible with pandas copy on write #276

rmnldwg opened this issue Apr 4, 2024 · 0 comments

Comments

@rmnldwg
Copy link

rmnldwg commented Apr 4, 2024

First of all, thanks for the nice package! This allows me to nicely visualize my research!

However, I stumbled across this issue: Pandas recommends to turn on "copy-on-write" as it will become the default in pandas 3. But this feature breaks the upsetplot package.

Here a minimal script that reproduces the failure:

import pandas as pd
from upsetplot import plot, generate_counts

pd.options.mode.copy_on_write = True

plot(generate_counts())

This raises the following exception:

Traceback (most recent call last):
  File "/home/user/test.py", line 6, in <module>
    plot(generate_counts())
  File "/home/user/.venv/lib/python3.10/site-packages/upsetplot/plotting.py", line 1158, in plot
    return UpSet(data, **kwargs).plot(fig)
  File "/home/user/.venv/lib/python3.10/site-packages/upsetplot/plotting.py", line 1098, in plot
    self.plot_matrix(matrix_ax)
  File "/home/user/.venv/lib/python3.10/site-packages/upsetplot/plotting.py", line 810, in plot_matrix
    ax.scatter(
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/__init__.py", line 1465, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 4744, in scatter
    collection = mcoll.PathCollection(
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/collections.py", line 1027, in __init__
    super().__init__(**kwargs)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/collections.py", line 174, in __init__
    self.set_edgecolor(edgecolors)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/collections.py", line 834, in set_edgecolor
    self._set_edgecolor(c)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/collections.py", line 813, in _set_edgecolor
    self._edgecolors = mcolors.to_rgba_array(c, self._alpha)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/colors.py", line 505, in to_rgba_array
    rgba = np.array([to_rgba(cc) for cc in c])
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/colors.py", line 505, in <listcomp>
    rgba = np.array([to_rgba(cc) for cc in c])
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/colors.py", line 302, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/home/user/.venv/lib/python3.10/site-packages/matplotlib/colors.py", line 391, in _to_rgba_no_colorcycle
    raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
ValueError: Invalid RGBA argument: nan

And even with copy-on-write set to False, pandas spits out a lot of warnings like this one:

ChainedAssignmentError: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
When using the Copy-on-Write mode, such inplace method never works to update the original DataFrame or Series, 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)' instead, to perform the operation inplace on the original object.

I was using the following setup to run the minimal "working" example:

OS Ubuntu 22.04.4 LTS on Windows 10 x86_64
Python 3.10.12
matplotlib 3.8.3
pandas 2.2.1
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

1 participant