fix: select Shapley Value column before aggregating in plot_global_feat - #63
Open
daniel-n-silva wants to merge 1 commit into
Open
daniel-n-silva wants to merge 1 commit into
daniel-n-silva wants to merge 1 commit into
Conversation
feat_data.groupby('Feature').mean() raises
"TypeError: agg function failed [how->mean,dtype->object]" under
pandas >= 2.0. Global feature explanations produced by feat_explain_all
carry an 'Entity' column, which is of object dtype whenever the entity
identifier is a string (as in the AReM example notebook), and
filter_dataset forwards it unchanged to plot_global_feat.
Selecting the column before aggregating skips the other columns
entirely, working on both old and new pandas without numeric_only=True.
The result is identical when no extra columns are present.
Fixes feedzai#62.
daniel-n-silva
force-pushed
the
fix/groupby-pandas2-compat
branch
from
September 11, 2026 18:10
3938db7 to
d1c6500
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
plot_global_feat()raisesTypeError: agg function failed [how->mean,dtype->object]under pandas >= 2.0.Root cause
feat_data.groupby('Feature').mean()['Shapley Value']aggregates every column first and selectsShapley Valueafterwards. Global feature explanations produced byfeat_explain_allalways carry anEntitycolumn, which ends up asobjectdtype whenever the entity identifier is a string (as in theAReM.ipynbexample notebook) —feat_data.astype(...)never casts it.filter_datasetforwards this column unchanged intoplot_global_feat. Older pandas silently dropped non-numeric columns before averaging; pandas >= 2.0 raises instead.Fix
Select the
Shapley Valuecolumn before aggregating, so the other columns are never touched:Identical result when no extra columns are present; works on both old and new pandas without needing
numeric_only=True.Fixes #62.
Test plan
TypeErrorlocally with pandas 2.3.3 using the real column set produced byfeat_explain_all(Random Seed,NSamples,Feature,Shapley Value,Entity,Tolerance) with a stringEntitycolumnSeries.name/index.nameas beforegroupby(...).mean()call sites insrc/(event_level.py:104,pruning.py:92) — both already select/aggregate safely, no change needed there