ueshin commented on code in PR #54382:
URL: https://github.com/apache/spark/pull/54382#discussion_r2849166768
##########
python/pyspark/sql/pandas/conversion.py:
##########
@@ -998,16 +1004,21 @@ def _create_from_pandas_with_arrow(
step = step if step > 0 else len(pdf)
pdf_slices = (pdf.iloc[start : start + step] for start in range(0,
len(pdf), step))
- # Create Arrow batches directly using the standalone function
- arrow_batches = [
- create_arrow_batch_from_pandas(
- [(c, t) for (_, c), t in zip(pdf_slice.items(), spark_types)],
- timezone=timezone,
- safecheck=safecheck,
- prefers_large_types=prefers_large_var_types,
- )
- for pdf_slice in pdf_slices
- ]
+ # Handle the 0-column case separately to preserve row count.
+ # pa.RecordBatch.from_pandas preserves num_rows via pandas index
metadata.
+ if len(pdf.columns) == 0:
+ arrow_batches = [pa.RecordBatch.from_pandas(pdf_slice) for
pdf_slice in pdf_slices]
Review Comment:
If this works more efficiently, shall we also use this in the similar parts,
like:
-
https://github.com/apache/spark/blob/1e31b772e4f5d183ab2bab1b9cda4426982f2113/python/pyspark/sql/connect/session.py#L626
-
https://github.com/apache/spark/blob/1e31b772e4f5d183ab2bab1b9cda4426982f2113/python/pyspark/sql/conversion.py#L289
It can be in a separate PR, though.
--
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]