Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions python/pyspark/sql/pandas/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,8 @@ def _convert_arrow_table_to_pandas(
error_on_duplicated_field_names = True
struct_handling_mode = "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 arrow_table.num_rows == 0:
# For empty tables, create empty Series to preserve dtypes
column_data = (
pd.Series([], name=temp_col_names[i], dtype="object") for i in range(len(schema.fields))
)
else:
# For non-empty tables, convert arrow columns directly
column_data = (arrow_col.to_pandas(**pandas_options) for arrow_col in arrow_table.columns)
# Convert arrow columns to pandas Series
column_data = (arrow_col.to_pandas(**pandas_options) for arrow_col in arrow_table.columns)

# Apply Spark-specific type converters to each column
pdf = pd.concat(
Expand Down