Skip to content

[Repo Assist] fix(interpreters): add observed=True to groupby in ConfounderDistributionInterpreter - #1755

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-confounder-dist-interpreter-groupby-observed-20260814-890083a81295369b
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-confounder-dist-interpreter-groupby-observed-20260814-890083a81295369b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.

Problem

ConfounderDistributionInterpreter.interpret() calls groupby() twice without observed=True:

# line 84
barplot_df_before = df.groupby([self.var_name, treated]).size().reset_index(name="count")

# line 87
barplot_df_after = df.groupby([self.var_name, treated]).agg({"weight": np.sum}).reset_index()

Since this interpreter is only used with var_type="discrete" (the "continuous" path raises NotImplementedError), the grouped columns are always discrete/categorical. pandas ≥ 2.2 emits a FutureWarning for every such call, and pandas 3.x changed the default from observed=False to observed=True.

Without observed=True, when any of the grouped columns is a pandas Categorical, the result can include empty groups for categories not present in the data, inflating the count/weight plots with spurious zero bars.

Fix

Add observed=True to both groupby calls.

Relation to existing PRs

PR #1732 fixed analogous groupby calls in:

  • propensity_balance_interpreter.py
  • propensity_score_stratification_estimator.py
  • distance_matching_estimator.py

This PR completes the fix for the remaining ConfounderDistributionInterpreter.

Test Status

The existing interpreter tests pass. Direct tests for this interpreter require matplotlib and propensity score weights, so they are marked @pytest.mark.advanced.

Linting and formatting checks pass (poe lint, poe format_check).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

…tionInterpreter

pandas >= 2.2 emits FutureWarning when groupby() is called on a
DataFrame that contains categorical columns without the observed=True
keyword argument; pandas 3.x will change the default.

ConfounderDistributionInterpreter.interpret() performs two groupby
calls on [var_name, treatment_variable] pairs without observed=True.
Since this interpreter is only used with discrete/categorical variables
(the 'continuous' path raises NotImplementedError), this warning fires
on every call.

Fix: add observed=True to both groupby calls.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor Author

This PR is stale because it has been open for 60 days with no activity.

@github-actions github-actions Bot added the stale label Oct 14, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants