Skip to content

Conversation

@codingabhiroop
Copy link
Contributor

@codingabhiroop codingabhiroop commented Jan 4, 2026

PR summary

violinplot currently fails silently when a dataset contains NaN values, aside
from a low-level NumPy warning, which can be confusing for users.

This PR filters NaN values in cbook.violin_stats, emits a RuntimeWarning,
and allows violins with valid data to be plotted. Datasets consisting entirely
of NaNs are skipped.

This behavior is consistent with other plotting functions such as hist.

CI Note: Failing tests (WebAgg, GTK/Tk/Qt backends, Windows_py312) are unrelated to this PR.
This PR only touches core plotting logic and test_axes.py. Failures are due to headless/ARM/Windows CI environments.

PR checklist

  • closes [Bug]: violinplot with nan values fails silently #30355
  • new and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New Features and API Changes are noted with a directive and release note
  • [N/A] Documentation complies with general and docstring guidelines

@timhoffm
Copy link
Member

timhoffm commented Jan 6, 2026

Reconsidering: Do we need to warn at all? This is a bit of a philosophic question: Is NaN considered just a placeholder for "no value"? In that case it is reasonably to silently drop NaNs. Or is NaN marking "undefined value" in which case a warning would be reasonable.

Since plt.plot() and plt.hist() do not warn on NaNs I assume we tend to go with the first interpretation, even though we have never spelled that out explicitly. Do we have precedence for warning on NaNs?

@scottshambaugh
Copy link
Contributor

My preference would also be to not warn and instead skip NaN values, like we do for hist. Sorry @codingabhiroop, I think this should get discussed more in the original issue before we commit to a solution

@codingabhiroop
Copy link
Contributor Author

Thanks for the clarification — that makes sense.

Happy to hold off on further changes until there’s agreement in the original issue, and I’m also happy to update this PR like removing the warning entirely once a direction is decided.

@timhoffm
Copy link
Member

timhoffm commented Jan 9, 2026

I'll decide here: silently dropping NaNs is the way to go.

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

Successfully merging this pull request may close these issues.

[Bug]: violinplot with nan values fails silently

4 participants