Skip to content

fix: preserve entities without community assignments in level filter (fixes #2348)#2368

Open
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-2348-community-level-nan
Open

fix: preserve entities without community assignments in level filter (fixes #2348)#2368
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-2348-community-level-nan

Conversation

@hanhan761
Copy link
Copy Markdown

Summary

_filter_under_community_level\ uses \df[df.level <= community_level]\ which evaluates to \False\ for NaN values. Entities not assigned to any community by Leiden detection get \level = NaN\ after a left join and are silently dropped, causing the query engine to operate on a drastically reduced entity set with no warning.

Changes

\graphrag/query/indexer_adapters.py: Added | df.level.isna()\ to the filter condition so that entities without community assignments are preserved. Since "not in any community" is not the same as "in a community above the requested level," retaining them is the semantically correct behavior.

Related

Fixes #2348

@hanhan761 hanhan761 requested a review from a team as a code owner May 30, 2026 08:38
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.

_filter_under_community_level silently drops all entities without community assignments due to NaN comparison

1 participant