[SPARK-54316][PYTHON] Consolidate GroupPandasIterUDFSerializer with GroupPandasUDFSerializer #53043
+70
−112
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.
What changes were proposed in this pull request?
This PR consolidates
GroupPandasIterUDFSerializerwithGroupPandasUDFSerializerto eliminate code duplication and improve maintainability.Modified
GroupPandasUDFSerializer(python/pyspark/sql/pandas/serializers.py):use_iteratorparameter to support both regular and iterator modes_convert_batches_to_pandashelper methodload_stream()anddump_stream()methods to handle both modes with minimal branchingWhy are the changes needed?
When
Iterator[pandas.DataFrame]API was added togroupBy().applyInPandas()in SPARK-53614 (#52716), a newGroupPandasIterUDFSerializerclass was created. However, this class is nearly identical toGroupPandasUDFSerializer, differing only in whether batches are processed lazily (iterator mode) or all at once (regular mode).Does this PR introduce any user-facing change?
No.
How was this patch tested?
All existing tests pass without modification:
test_apply_in_pandas_iterator_*ApplyInPandasTestsWas this patch authored or co-authored using generative AI tooling?
Co-Generated-by: Cursor with Claude 4.5 Sonnet