fix: preserve dictionary encoding in to_arrow_batch_reader#3595
Open
avison9 wants to merge 1 commit into
Open
Conversation
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.
Rationale for this change
DataScan.to_arrow_batch_reader(dictionary_columns=("col",))silently dropped dictionaryencoding — callers got plain string arrays instead of
dictionary<values=string, indices=int32>,with no error or warning. The eager equivalent
to_arrow(dictionary_columns=...)workedcorrectly. This fixes the streaming path to match.
Before:
After:
Root cause:
_to_arrow_batch_reader_via_file_scan_tasksbuilttarget_schemaviaschema_to_pyarrow(which returns plain types), then called.cast(target_schema)on theRecordBatchReader.ArrowScan.to_record_batchescorrectly yielded dictionary-encodedbatches, but the cast converted them back to plain types. The fix rebuilds
target_schemawith
pa.dictionary(pa.int32(), field.type)for each column indictionary_columnsbeforethe cast, so the encoding is preserved end-to-end.
Are these changes tested?
Yes. Added
test_to_arrow_batch_reader_preserves_dictionary_columnsintests/io/test_pyarrow.py— writes a two-column Parquet file and asserts that_to_arrow_batch_reader_via_file_scan_tasksreturns a dictionary-encodedlabelcolumnwhile leaving
idas plainint32.Are there any user-facing changes?
Yes —
to_arrow_batch_reader(dictionary_columns=...)now correctly returns dictionary-encodedarrays for the requested columns, matching the documented behaviour and the existing
to_arrowpath. Please apply the
changeloglabel to this PR — the project has no changelog file/newsfragmentrequirement (no
CONTRIBUTING.md); release notes are generated from labeled, merged PR titles.