Skip to content

fix: GroupBy(ValueDrift) widget title now reflects group-by context#1881

Open
SuryaSunil1326 wants to merge 2 commits into
evidentlyai:mainfrom
SuryaSunil1326:fix/groupby-valuedrift-widget-title
Open

fix: GroupBy(ValueDrift) widget title now reflects group-by context#1881
SuryaSunil1326 wants to merge 2 commits into
evidentlyai:mainfrom
SuryaSunil1326:fix/groupby-valuedrift-widget-title

Conversation

@SuryaSunil1326
Copy link
Copy Markdown

Problem

When ValueDrift is wrapped in GroupBy, the counter widget in the HTML report always shows the hardcoded label "Drift in column '<col>'" — it never includes the group-by context (group by '<col>' for label: '<label>'). Reported in #1706.

Root cause

ValueDriftCalculation._render() hardcoded the CounterData label string independently of display_name(). The GroupByMetricCalculation patches display_name on the inner calculation before calling calculate(), but _render() ignored it.

Fix

Add an optional title parameter to _render() and pass self.display_name() when calling it from calculate(). Since display_name is already patched to the full group-by string in the GroupBy context, the widget label picks it up automatically.

Standalone ValueDrift: title = "Value drift for col1"
GroupBy(ValueDrift): title = "Value drift for col1 group by 'group' for label: 'a'"

Testing

Added tests/future/metrics/test_group_by_metric.py with two tests:

  • test_group_by_value_drift_widget_title_includes_group_context — asserts the widget label contains "group by" and "for label:" when wrapped in GroupBy
  • test_standalone_value_drift_widget_title — asserts standalone ValueDrift label contains the column name and no "group by" text

All 1414 existing future metrics tests pass.

AI assistance: Written with Claude Code. All code reviewed, tested, and verified by the author.

The hardcoded fill value (0.0001 or min/1e6) for zero-probability bins
in get_binned_data caused two problems:

1. When min non-zero percent <= 0.0001, filling with min/1e6 produced
   an astronomically small value that inflated KL divergence scores.
2. Reference and current distributions received different fill values,
   introducing asymmetry in divergence metrics.

Fix: compute a single fill value as min_nonzero_both / 10, where
min_nonzero_both is the smallest non-zero probability across both
distributions. This guarantees the fill is always smaller than any
genuine probability and is applied symmetrically.

Fixes evidentlyai#334
When ValueDrift is wrapped in GroupBy, the counter widget label was
hardcoded as "Drift in column '<col>'" regardless of the GroupBy
label. Thread display_name() through _render() so the patched name
("... group by '<col>' for label: '<label>'") appears in the widget.

Fixes evidentlyai#1706

AI assistance: Written with Claude Code. All code reviewed, tested, and
verified by the author.
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.

2 participants