Yicong-Huang commented on code in PR #54382:
URL: https://github.com/apache/spark/pull/54382#discussion_r2849215122
##########
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:
thanks. Let's address them with a separate PR, since this one is for a bug
fix.
--
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]