Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve binning in Series.hist with bin_count when all values are the same #20034

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

mcrumiller
Copy link
Contributor

@mcrumiller mcrumiller commented Nov 27, 2024

Closes #20030.

I added a skip condition to the test_hist_rand to address "flaky failure" in the same-value case, since including it would increase the complexity of the test. It's easier to just include the separate test.

New behavior uses a unit interval, as it does in the single-value case:

>>> pl.Series([1, 1]).hist(bin_count=2)
shape: (2, 3)
┌────────────┬────────────┬───────┐
│ breakpoint ┆ category   ┆ count │
│ ---        ┆ ---        ┆ ---   │
│ f64        ┆ cat        ┆ u32   │
╞════════════╪════════════╪═══════╡
│ 1.0        ┆ (0.5, 1.0] ┆ 2     │
│ 1.5        ┆ (1.0, 1.5] ┆ 0     │
└────────────┴────────────┴───────┘

I think this could use a further improvement and should probably only have a single bin, but that can be a different discussion.

@mcrumiller mcrumiller changed the title Fix: hist with bin_count produces wrong result if all values are the same Fix: hist with bin_count produces wrong result if all values are the same Nov 27, 2024
@mcrumiller mcrumiller changed the title Fix: hist with bin_count produces wrong result if all values are the same fix: hist with bin_count produces wrong result if all values are the same Nov 27, 2024
@mcrumiller mcrumiller changed the title fix: hist with bin_count produces wrong result if all values are the same fix: Series.hist with bin_count produces wrong result if all values are the same Nov 27, 2024
@mcrumiller
Copy link
Contributor Author

mcrumiller commented Nov 27, 2024

Why is the PR title check failing?

Edit: the PR regex is:

^(build|chore|ci|depr|docs|feat|fix|perf|refactor|release|test)(\\((python|rust)\\!?(,(python|rust)\\!?)?\\))?\\!?\\: [A-Z].*[^\\.\\!\\?,… ]$

which doesn't allow the message to start with a backtick.

@mcrumiller mcrumiller changed the title fix: Series.hist with bin_count produces wrong result if all values are the same fix: Improve binning in Series.hist with bin_count when all values are the same Nov 27, 2024
@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Nov 27, 2024
@mcrumiller mcrumiller marked this pull request as ready for review November 27, 2024 16:48
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.50%. Comparing base (7c97625) to head (cf4b509).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #20034    +/-   ##
========================================
  Coverage   79.49%   79.50%            
========================================
  Files        1556     1562     +6     
  Lines      216527   216910   +383     
  Branches     2456     2458     +2     
========================================
+ Hits       172136   172448   +312     
- Misses      43833    43903    +70     
- Partials      558      559     +1     

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

@ritchie46 ritchie46 merged commit 83b5042 into pola-rs:main Nov 28, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.hist with bin_count produces wrong result if all values are the same
2 participants