fix: preserve entities without community assignment in _filter_under_community_level (fixes #2348)#2370
Open
hanhan761 wants to merge 1 commit into
Open
Conversation
06b21f5 to
440a8cc
Compare
Closes microsoft#2348 Entities without community assignments have level=NaN after the left join with community membership data. The filter df[df.level <= x] evaluates to False for NaN in NumPy/pandas, silently dropping all unassigned entities with no warning. This causes CLI queries (graphrag query --method local/global/drift) to operate on a drastically reduced entity set, often producing empty or degraded results. Fix: change the filter to df[(df.level <= community_level) | df.level.isna()] so that entities without community assignments are preserved.
440a8cc to
cbcb854
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
Preserves entities without community assignments in
_filter_under_community_levelinstead of silently dropping them.Issue
Closes #2348
Root Cause
The filter
df[df.level <= community_level]evaluates toFalsefor any row wherelevelisNaN. Entities not assigned to any community by the Leiden algorithm havelevel=NaNafter the left join with community membership data. This silently drops all unassigned entities — in some datasets, 93% or more of the entity set — causing CLI queries to return empty or degraded results with no warning.Fix
Changed
_filter_under_community_levelto use the pandas-safe expression:This preserves entities without community assignments while still applying the level filter to assigned entities. Entities with
level=NaNare not "above the requested level" — they simply have no community, and should not be excluded.Edge Cases Not Covered
community_level=Nonepath (which skips the filter entirely) is unaffected.Verification
3 new unit tests: