gaogaotiantian commented on code in PR #53045:
URL: https://github.com/apache/spark/pull/53045#discussion_r2525238611


##########
python/pyspark/sql/connect/client/core.py:
##########
@@ -1030,37 +1031,15 @@ def to_pandas(
                 error_on_duplicated_field_names = True
                 struct_in_pandas = "dict"
 
-            # SPARK-51112: If the table is empty, we avoid using pyarrow 
to_pandas to create the
-            # DataFrame, as it may fail with a segmentation fault.
-            if table.num_rows == 0:
-                # For empty tables, create empty Series with converters to 
preserve dtypes
-                pdf = pd.concat(
-                    [
-                        _create_converter_to_pandas(
-                            field.dataType,
-                            field.nullable,
-                            timezone=timezone,
-                            struct_in_pandas=struct_in_pandas,
-                            
error_on_duplicated_field_names=error_on_duplicated_field_names,
-                        )(pd.Series([], name=temp_col_names[i], 
dtype="object"))
-                        for i, field in enumerate(schema.fields)
-                    ],
-                    axis="columns",
-                )
-            else:
-                pdf = pd.concat(
-                    [
-                        _create_converter_to_pandas(
-                            field.dataType,
-                            field.nullable,
-                            timezone=timezone,
-                            struct_in_pandas=struct_in_pandas,
-                            
error_on_duplicated_field_names=error_on_duplicated_field_names,
-                        )(arrow_col.to_pandas(**pandas_options))
-                        for arrow_col, field in zip(table.columns, 
schema.fields)
-                    ],
-                    axis="columns",
-                )
+            pdf = _convert_arrow_table_to_pandas(
+                table,
+                schema.fields,

Review Comment:
   The problem is when in the future, you need to add an extra field, you have 
to count where you should add it. Also it wouldn't be obvious if someone use 
the wrong order.
   
   ```python
   pdf = _convert_arrow_table_to_pandas(
       table,
       schema.fields,
       temp_col_names,
       timezone,
       error_on_duplicated_field_names,
       struct_in_pandas,
       pandas_options,
   )
   ```
   
   It's super unobvious that the code above is wrong - and when you look at it 
only, you don't know how to fix it.



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