10000 Axes.pie([0, 0]) crashes with “cannot convert float NaN to integer” when all slice sizes are zero · Issue #30007 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Axes.pie([0, 0]) crashes with “cannot convert float NaN to integer” when all slice sizes are zero #30007
Closed
@PouyaSA96

Description

@PouyaSA96

Calling ax.pie() with all-zero data leads to an internal NaN→int conversion failure, rather than a clean “all zero input” error or an empty plot.

Reproducible example

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.pie([0, 0], labels=["A", "B"])
fig.savefig("out.png")`

Traceback

RuntimeWarning: invalid value encountered in divide
  x = x / sx
...
  File ".../matplotlib/axes/_axes.py", line 3409, in pie
    w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
      ...
  File ".../matplotlib/patches.py", line 1264, in _recompute_path
    arc = Path.arc(theta1, theta2)
  File ".../matplotlib/path.py", line 961, in arc
    n = int(2 ** np.ceil((eta2 - eta1) / halfpi))
ValueError: cannot convert float NaN to integer

Expected behavior

Either:

Render an empty/placeholder pie when slice‐sizes sum to zero

Or raise a clear ValueError("All wedge sizes zero") before entering the NaN conversion

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0