You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2023/07/26 04:29:21 UTC

[GitHub] [spark] ueshin commented on a diff in pull request #42161: [SPARK-44479][PYTHON] Fix ArrowStreamPandasUDFSerializer to accept no-column pandas DataFrame

ueshin commented on code in PR #42161:
URL: https://github.com/apache/spark/pull/42161#discussion_r1274361664


##########
python/pyspark/sql/pandas/serializers.py:
##########
@@ -385,37 +385,28 @@ def _create_struct_array(self, df, arrow_struct_type):
         """
         import pyarrow as pa
 
-        # Input partition and result pandas.DataFrame empty, make empty Arrays with struct
-        if len(df) == 0 and len(df.columns) == 0:
-            arrs_names = [
-                (pa.array([], type=field.type), field.name) for field in arrow_struct_type
-            ]
+        if len(df.columns) == 0:
+            return pa.array([{}] * len(df), arrow_struct_type)

Review Comment:
   For example:
   
   ```py
   >>> pdf = pd.DataFrame(index=[1,2,3])
   >>> pdf
   Empty DataFrame
   Columns: []
   Index: [1, 2, 3]
   >>> len(pdf)
   3
   >>> len(pdf.columns)
   0
   ```



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org