BryanCutler commented on a change in pull request #24981: [SPARK-27463][PYTHON] 
Support Dataframe Cogroup via Pandas UDFs
URL: https://github.com/apache/spark/pull/24981#discussion_r312265921
 
 

 ##########
 File path: python/pyspark/serializers.py
 ##########
 @@ -401,6 +427,22 @@ def __repr__(self):
         return "ArrowStreamPandasUDFSerializer"
 
 
+class InterleavedArrowStreamPandasSerializer(ArrowStreamPandasUDFSerializer):
+
+    def __init__(self, timezone, safecheck, assign_cols_by_name):
+        super(InterleavedArrowStreamPandasSerializer, self).__init__(timezone, 
safecheck, assign_cols_by_name)
+
+    def load_stream(self, stream):
+        """
+        Deserialize ArrowRecordBatches to an Arrow table and return as a list 
of pandas.Series.
+        """
+        reader = InterleavedArrowReader(stream)
 
 Review comment:
   `ArrowStreamSerializer` doesn't need to know how many streams in total are 
being sent. Calling `ArrowStreamSerializer.load_stream` will return an iterator 
that loads 1 single Arrow stream and then stops. It's basically what you are 
already doing in `InterleavedArrowReader._read_df`. You would just wrap in a 
while loop. Taking what you have already, for example:
   
   ```python
    def load_stream(self, stream):
       dataframes_in_group = None
   
       while dataframes_in_group is None or dataframes_in_group > 0:
         dataframes_in_group = read_int(self._stream)
   
         if dataframes_in_group == 2:
             batch1 = [batch for batch in 
ArrowStreamSerializer.load_stream(stream)]
             batch2 = [batch for batch in 
ArrowStreamSerializer.load_stream(stream)]
             yield ([self.arrow_to_pandas(c) for c in 
pa.Table.from_batches(batch1).itercolumns()],
                    [self.arrow_to_pandas(c) for c in 
pa.Table.from_batches(batch2).itercolumns()])
   
         elif dataframes_in_group != 0:
             raise ValueError(
                   'Received Invalid number of dataframes in group 
{0}'.format(dataframes_in_group))
   
   ```
   
   I think this is the same as what's in `InterleavedArrowReader`, just 
condensed a little

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to