FFFF TypeError with NumPy 2.4+ (Strict scalar conversion failure) · Issue #301 · jnothman/UpSetPlot · GitHub
[go: up one dir, main page]

Skip to content

TypeError with NumPy 2.4+ (Strict scalar conversion failure) #301

Open

Description

@durr1602

Hi all! I imagine this won't get much attention but, let's say for future reference, if the project gets reborn from its ashes..

The whole Pandas 2.0+ had some important changes, which meant we needed to use different methods to manipulate dataframes. I'm currently using this fork, which was super useful to get rid of all the future warnings.

Now, a similar wave of important changes are happening with Numpy 2.4, notably with scalar casting which has become stricter and will raise bugs with the fork I'm using, but I'm guessing this repo as well.

In my case, calling plt.savefig(..., format="svg") fails with: TypeError: only 0-dimensional arrays can be converted to Python scalars (or ValueError: setting an array element with a sequence). This is with Numpy 2.4.0 but the bug isn't there with Numpy 2.3.5.

Gemini (I know) says "Some internal calculations in upsetplot (likely related to bar labels or category positioning) are passing 1-item numpy.ndarray objects as coordinates to Matplotlib text elements instead of raw Python floats. While the PNG renderer is often forgiving, the SVG renderer explicitly calls float() on coordinates, which now triggers this failure."

Suggested fix:

# Instead of 
ax.text(x, y, label) 
# Use
ax.text(float(np.ravel(x)[0]), float(np.ravel(y)[0]), label)

Finally, I should note that I'm using Matplotlib 3.10.3 but Matplotlib considers that it should fail if numpy.ndarray are passed, so it's upsetplot's responsibility to cast, taking into account Numpy's new behavior.

For my needs, I think I'll downgrade Numpy for now.

Have a nice day!

Activity

  1. added 2 commits that reference this issue on Jan 7, 2026
  2. dysby commented on Jan 9, 2026

    @dysby

    Thank you, very timely reported, just had the same issue and it works great by patching all ax.text in plotting.py

    ax.text(
        float(np.ravel(rect.get_x() + rect.get_width() * 0.5)[0]),
        float(np.ravel(height + margin)[0]),
        fmt.format(*make_args(height)),
        ha="center",
        va="bottom",
    )
  3. added a commit that references this issue on Jan 14, 2026
    08f0648
  4. jnareb commented on Mar 5, 2026

    @jnareb

    I have the same issue when trying to use the show_counts=True feature.

    Here is the minimal example (modified from "Basic: Examples with generated data"):

    from matplotlib import pyplot as plt
    from upsetplot import generate_counts, plot
    
    example = generate_counts()
    plot(example, show_counts=True)
    plt.suptitle("Ordered by degree")
    plt.show()

    matplotlib==3.10.8
    numpy==2.4.0
    pandas==2.3.3

    Here is the full error message:
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    File ~/.venv/lib/python3.13/site-packages/IPython/core/formatters.py:402, in BaseFormatter.__call__(self, obj)
        400     pass
        401 else:
    --> 402     return printer(obj)
        403 # Finally look for special method names
        404 method = get_real_method(obj, self.print_method)
    
    File ~/.venv/lib/python3.13/site-packages/IPython/core/pylabtools.py:170, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
        167     from matplotlib.backend_bases import FigureCanvasBase
        168     FigureCanvasBase(fig)
    --> 170 fig.canvas.print_figure(bytes_io, **kw)
        171 data = bytes_io.getvalue()
        172 if fmt == 'svg':
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/backend_bases.py:2157, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
       2154     # we do this instead of `self.figure.draw_without_rendering`
       2155     # so that we can inject the orientation
       2156     with getattr(renderer, "_draw_disabled", nullcontext)():
    -> 2157         self.figure.draw(renderer)
       2158 if bbox_inches:
       2159     if bbox_inches == "tight":
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/artist.py:94, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
         92 @wraps(draw)
         93 def draw_wrapper(artist, renderer, *args, **kwargs):
    ---> 94     result = draw(artist, renderer, *args, **kwargs)
         95     if renderer._rasterizing:
         96         renderer.stop_rasterizing()
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
         68     if artist.get_agg_filter() is not None:
         69         renderer.start_filter()
    ---> 71     return draw(artist, renderer)
         72 finally:
         73     if artist.get_agg_filter() is not None:
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/figure.py:3257, in Figure.draw(self, renderer)
       3254             # ValueError can occur when resizing a window.
       3256     self.patch.draw(renderer)
    -> 3257     mimage._draw_list_compositing_images(
       3258         renderer, self, artists, self.suppressComposite)
       3260     renderer.close_group('figure')
       3261 finally:
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
        132 if not_composite or not has_images:
        133     for a in artists:
    --> 134         a.draw(renderer)
        135 else:
        136     # Composite any adjacent images together
        137     image_group = []
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
         68     if artist.get_agg_filter() is not None:
         69         renderer.start_filter()
    ---> 71     return draw(artist, renderer)
         72 finally:
         73     if artist.get_agg_filter() is not None:
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/axes/_base.py:3226, in _AxesBase.draw(self, renderer)
       3223 if artists_rasterized:
       3224     _draw_rasterized(self.get_figure(root=True), artists_rasterized, renderer)
    -> 3226 mimage._draw_list_compositing_images(
       3227     renderer, self, artists, self.get_figure(root=True).suppressComposite)
       3229 renderer.close_group('axes')
       3230 self.stale = False
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
        132 if not_composite or not has_images:
        133     for a in artists:
    --> 134         a.draw(renderer)
        135 else:
        136     # Composite any adjacent images together
        137     image_group = []
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
         68     if artist.get_agg_filter() is not None:
         69         renderer.start_filter()
    ---> 71     return draw(artist, renderer)
         72 finally:
         73     if artist.get_agg_filter() is not None:
    
    File ~/.venv/lib/python3.13/site-packages/matplotlib/text.py:762, in Text.draw(self, renderer)
        760 if np.ma.is_masked(y):
        761     y = np.nan
    --> 762 posx = float(self.convert_xunits(x))
        763 posy = float(self.convert_yunits(y))
        764 posx, posy = trans.transform((posx, posy))
    
    TypeError: only 0-dimensional arrays can be converted to Python scalars
    
  5. durr1602 commented on Mar 12, 2026

    @durr1602
    Author

    @jnareb have you tried the patch proposed by @dysby ? you can install my fork by specifying this in your requirements file:

    upsetplot @ git+https://github.com/durr1602/UpSetPlot.git@7fa2661
    

    I've tried your minimal example with your exact package versions and it works fine :)

  6. jnareb commented on Mar 18, 2026

    @jnareb

    @jnareb have you tried the patch proposed by @dysby ? you can install my fork by specifying this in your requirements file:

    upsetplot @ git+https://github.com/durr1602/UpSetPlot.git@7fa2661
    

    Thanks. That works for me.

  7. added a commit that references this issue on Sep 11, 2026
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