Yicong-Huang commented on code in PR #54144:
URL: https://github.com/apache/spark/pull/54144#discussion_r2766108058
##########
python/pyspark/sql/connect/session.py:
##########
@@ -621,22 +621,33 @@ def createDataFrame(
safecheck =
configs["spark.sql.execution.pandas.convertToArrowArraySafely"]
- _table = pa.Table.from_batches(
- [
- create_arrow_batch_from_pandas(
- [(c, st) for (_, c), st in zip(data.items(),
spark_types)],
- timezone=cast(str, timezone),
- safecheck=safecheck == "true",
- prefers_large_types=prefers_large_types,
- )
- ]
- )
+ # Handle the 0-column case separately to preserve row count.
+ if len(data.columns) == 0:
+ # For 0 rows, need explicit struct type; otherwise pa.array
infers null type
+ if len(data) == 0:
Review Comment:
oh, I can combine them to
```
>>> pa.array([{}] * 0, type=pa.struct([]))
<pyarrow.lib.StructArray object at 0x1115cf700>
-- is_valid: all not null
```
--
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]