holdenk commented on code in PR #53045:
URL: https://github.com/apache/spark/pull/53045#discussion_r2529335866
##########
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",
- )
Review Comment:
Could we not also unify the ` # Restore original column names
(including duplicates)
pdf.columns = schema.names
else:
# empty columns
pdf = table.to_pandas(**pandas_options)` logic?
--
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]