Skip to content

Improve test suite: ridgeplot._hist - #365

Open
tpvasconcelos wants to merge 12 commits into
mainfrom
improve-test-hist
Open

Improve test suite: ridgeplot._hist#365
tpvasconcelos wants to merge 12 commits into
mainfrom
improve-test-hist

Conversation

@tpvasconcelos

@tpvasconcelos tpvasconcelos commented Dec 26, 2025

Copy link
Copy Markdown
Owner

Summary

Rewrites tests/unit/test_hist.py with a more comprehensive, better-organised test suite for ridgeplot._hist, and fixes the user-facing validation gaps surfaced by the behavioural review of those tests.

Test suite

  • Replace the shared module-level constants (SAMPLES_IN, X_OUT, ...) with parametrised, self-contained test cases: basic binning, single bin, uniform distribution, all-identical samples (zero-width range), and negative values
  • Fix the stale section headers that still referenced estimate_density_trace()/estimate_densities() (copied over from test_kde.py)
  • Add coverage for previously untested behaviour:
    • bin_samples() with sample_weights: flat-vector broadcast to all traces, and per-row weights in the shallow form (incl. broadcast to all traces within a multi-trace row)
    • Shape preservation for ragged rows in bin_samples()
    • Output normalisation to built-in floats (np.float64 is a subclass of float, so a plain isinstance() check wouldn't cut it)
    • Invariants: counts sum to the sample size (or to the sum of weights, when weighted), and bin centers stay within the data range (with a documented caveat for the degenerate all-identical-samples case)
    • Single-sample binning, empty samples, negative/all-zero weights, and weights/samples shape mismatches
  • Error handling: non-finite samples/weights (now incl. -inf) and mismatched weights lengths are parametrised and deduplicated via a shared NON_FINITE_VALUES constant

Bug fixes (validation gaps found while reviewing the tests)

  • Empty samples now raise a clear ValueError in both the histogram and KDE paths (previously: silent zero-count bins over numpy's default [0, 1] range, followed by a bare ZeroDivisionError from ridgeplot())
  • Negative and all-zero sample_weights now raise clear ValueErrors (previously: opaque crashes deep in the color interpolation logic)
  • Weights-length mismatch errors now include the actual lengths and mention flat-vector broadcasting; shallow-attrs row-count mismatches raise a clear message instead of a bare zip() error
  • Shared samples/weights validation is consolidated into a single helper used by both the histogram and KDE paths

Documentation

  • Fix the sample_weights parameter docs: no longer described as "KDE weights" (it applies to histogram binning too), and the three accepted forms (flat broadcast vector, shallow per-row list, full nested per-trace array) are now documented

Related

  • Surfaced {gh-issue}397 (support for custom bin edges) as a follow-up feature request

Signed-off-by: Tomas Pereira de Vasconcelos <tomasvasconcelos1@gmail.com>
@github-actions

This comment has been minimized.

@codecov

codecov Bot commented Dec 26, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (14e872d) to head (9845633).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #365   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          674       678    +4     
  Branches        88        88           
=========================================
+ Hits           674       678    +4     
Flag Coverage Δ
combined-src 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@tpvasconcelos
tpvasconcelos marked this pull request as draft December 26, 2025 13:44
@tpvasconcelos
tpvasconcelos marked this pull request as ready for review July 25, 2026 03:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39a77d3b32

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/unit/test_hist.py
Comment on lines +141 to +144
@pytest.mark.parametrize("non_finite", NON_FINITE_VALUES)
def test_rejects_non_finite_samples(non_finite: float) -> None:
with pytest.raises(ValueError, match="samples array should not contain any infs or NaNs"):
bin_trace_samples([1, 2, non_finite], nbins=2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove stale tests that reference deleted constants

The new non-finite-value cases duplicate rather than replace the existing tests at lines 71–74 and 172–180, while this patch deletes SAMPLES_IN, NBINS, and WEIGHTS. Consequently, collecting this file runs eight cases that raise NameError before reaching bin_trace_samples; the targeted pytest suite reports 8 failures. Delete those stale tests or make them self-contained so the unit suite passes.

AGENTS.md reference: AGENTS.md:L163-L163

Useful? React with 👍 / 👎.

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