fix(stat_summary_bin): emit the fallback warning instead of building it - #1129
Merged
has2k1 merged 1 commit intoSep 26, 2026
Merged
Conversation
`setup_params` constructs `PlotnineWarning(...)` and drops it on the floor, so falling back to `mean_se()` happens in complete silence. The commit that introduced this (827fd09, "Add default function to stat_summary_bin") replaced `raise PlotnineError("No summary function")` with the warning and even switched the import, so announcing the fallback was the intent; only the `warn()` call is missing. The sibling `stat_summary.setup_params` still raises on the same condition, and ggplot2 informs here too (`R/stat-summary-bin.R`: "No summary function supplied, defaulting to mean_se"). It matters because a misspelled argument, `fun=` instead of `fun_y=` for instance, silently yields a plausible and wrong plot. The stray comma in the message goes away with it, making the wording match ggplot2's.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1129 +/- ##
=======================================
Coverage 88.50% 88.50%
=======================================
Files 226 226
Lines 16613 16614 +1
Branches 2130 2130
=======================================
+ Hits 14703 14704 +1
Misses 1295 1295
Partials 615 615 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
|
@Rodrigo-Palma, thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
stat_summary_bin.setup_paramsbuilds aPlotnineWarningand throws it away:There is no
warn(...), and the module does not even import it, so the fallback tomean_se()happens in complete silence:It is the only instantiated-and-discarded warning or exception in
plotnine/:Why it is an oversight and not a decision
Three independent signals:
The commit that wrote the line. 827fd09 ("Add default function to
stat_summary_bin", closes stat_summary_bin no default summary function #528) deliberately turned an error into a warning, switching the import along with it:The message was written on purpose; only the
warn()call never made it in. Theraisethat used to make this visible went away and nothing took its place.The sibling.
stat_summary.setup_paramsstill raises on the very same condition (identicalkeystuple andif not any(...)block), and every other warning inplotnine/stats/goes throughwarn(msg, PlotnineWarning).ggplot2 informs here.
R/stat-summary-bin.R:cli::cli_inform("No summary function supplied, defaulting to {.fn mean_se}"). The wording in plotnine is the same sentence, stray comma aside.What it costs in practice: someone who mistypes the argument,
fun=instead offun_y=coming from ggplot2 3.4+, gets error bars nobody asked for and no hint that a default was substituted.The change
Call
warn, and drop the stray comma while the line is being touched, which makes the message read exactly like ggplot2's.Test
test_no_summary_function_warnsasserts the warning viap._build(), the same waytests/test_stat.pydoes.Before the fix:
After:
4 passedin that file.Full suite with the fix:
906 passed, 5 skipped, 1 xpassed, includingtests/test_lint_and_format.py. The new warning surfaces in the existingtest_setting_binwidth, which is exactly the documented fallback and does not fail anything, since the project does not setfilterwarnings = error.