Skip to content

Fix local_score_BDeu KeyError on pandas >= 2.0#267

Merged
kunwuz merged 1 commit into
py-why:mainfrom
v-shaal:fix/bdeu-get-group-pandas2
Jun 20, 2026
Merged

Fix local_score_BDeu KeyError on pandas >= 2.0#267
kunwuz merged 1 commit into
py-why:mainfrom
v-shaal:fix/bdeu-get-group-pandas2

Conversation

@v-shaal

@v-shaal v-shaal commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

local_score_BDeu groups by a single parent column and calls GroupBy.get_group((ij,)). On pandas >= 2.0 a single grouper expects the scalar key, so the 1-tuple raises KeyError — making GES with score_func='local_score_BDeu' unusable on any current pandas (the bug is in the latest release 0.1.4.7 and on main).

Try the scalar key first and fall back to the 1-tuple form, so BDeu works on both old and new pandas. The resulting scores match a direct boolean-mask computation, and tests/TestGES.py::test_ges_load_discrete_10_with_local_score_BDeu runs to completion.

local_score_BDeu groups by a single parent column and calls
GroupBy.get_group((ij,)). On pandas >= 2.0 a single grouper expects the scalar
key, so the 1-tuple raises KeyError — making GES with
score_func='local_score_BDeu' unusable on any current pandas (the bug is in the
latest release 0.1.4.7 and on main).

Try the scalar key first and fall back to the 1-tuple form, so BDeu works on
both old and new pandas. The resulting scores match a direct boolean-mask
computation, and tests/TestGES.py::test_ges_load_discrete_10_with_local_score_BDeu
runs to completion.
@kunwuz
kunwuz self-requested a review June 20, 2026 05:27

@kunwuz kunwuz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's great, thanks!

@kunwuz
kunwuz merged commit 83d6547 into py-why:main Jun 20, 2026
2 checks passed
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