Skip to content

fix(stat_summary_bin): give each bin its own width - #1133

Open
Rodrigo-Palma wants to merge 1 commit into
has2k1:mainfrom
Rodrigo-Palma:fix/summary-bin-width
Open

Rodrigo-Palma wants to merge 1 commit into
has2k1:mainfrom
Rodrigo-Palma:fix/summary-bin-width

Conversation

@Rodrigo-Palma

Copy link
Copy Markdown
Contributor

With uneven breaks, every summary gets the width of the last bin:

df = pd.DataFrame({"x": range(15), "y": range(15)})
p = ggplot(df, aes("x", "y")) + stat_summary_bin(
    breaks=np.array([0, 2, 10, 14]), fun_y=np.mean, geom="col"
)
p.build().layers[0].data[["xmin", "xmax"]]
# main:  (-1, 3), (4, 8), (10, 14)
# here:  (0, 2), (2, 10), (10, 14)

x already comes from each bin's centre; this takes width per bin the same way. geom_histogram with the same breaks gives (0, 2), (2, 10), (10, 14).

With uneven `breaks`, every summary got the width of the last bin, so
bars and crossbars spanned the wrong intervals. `x` was already taken
per bin from the bin centres; take `width` the same way, as stat_bin
and ggplot2 do.
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.87%. Comparing base (ac9cfce) to head (5f954fb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1133      +/-   ##
==========================================
- Coverage   88.87%   88.87%   -0.01%     
==========================================
  Files         229      229              
  Lines       17292    17291       -1     
  Branches     2203     2203              
==========================================
- Hits        15368    15367       -1     
  Misses       1295     1295              
  Partials      629      629              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant