Repository navigation
BUG: groupby/factorize on pyarrow dictionary dtype uses stale dictionary entries (GH#71828) - #71828
Merged
Merged
Conversation
…y contents (GH#71827) The stored dictionary of a pyarrow DictionaryArray can hold unreferenced, duplicate or null entries, so factorize the dictionary values, map the indices through those codes, and renumber by first appearance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fangchenli
approved these changes
Nov 12, 2026
fangchenli
left a comment
Member
There was a problem hiding this comment.
Not a blocker: string_view tests will fail after apache/arrow#50164 land.
8 tasks
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.
ArrowExtensionArray.factorizereturned a pyarrow dictionary array's stored dictionary as itsuniques. That dictionary is not a factorization of the values: it can keep entries no row references (e.g. after a boolean filter), hold duplicate or null entries, and be in any order. So on a dictionary-typed column, such as one read viaread_parquet(..., dtype_backend="pyarrow")from a file holding a Categorical,groupbyinvented groups for filtered-out values, split one value across two groups, and orderedsort=Falsegroups by dictionary order.The fix factorizes the (small) dictionaries' values, maps the indices through those codes, and renumbers by first appearance, so the N values are never hashed. When the chunks' dictionaries together are longer than the array (e.g. many parquet row groups each storing every category), it decodes and factorizes the values instead. Value types with no hash or
takekernel (list, struct,string_view) keep the stored dictionary as before, raising where that would mishandle a null (GH-66490).1M rows / 1000 string keys:
factorize2.2 ms, vs 13-15 ms for decode + re-encode.Supersedes GH-69024, a different approach written before GH-66490.
AI disclosure: drafted with Claude Code (
claude opus 5.5 (high)), which wrote the fix and tests and ran the review loop; I reviewed the result.