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
   ```
   
   or
   
   ```py
   >>> pd.DataFrame([tuple(), tuple(), tuple()])
   Empty DataFrame
   Columns: []
   Index: [0, 1, 2]
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to