CODERNSINGH opened a new pull request, #60521:
URL: https://github.com/apache/spark/pull/60521

   ### What changes were proposed in this pull request?
   
   In Spark Connect, `createDataFrame` no longer raises 
`CANNOT_INFER_EMPTY_SCHEMA` for an empty NumPy ndarray or an empty PyArrow 
Table when no schema is given. The empty-data check now applies only to inputs 
whose schema has to be inferred from rows. Empty ndarrays and Arrow Tables go 
through the existing conversion branches, which take the column types from the 
dtype / Arrow schema.
   
   ### Why are the changes needed?
   
   Classic PySpark accepts these inputs, Spark Connect rejects them:
   
   ```python
   import numpy as np
   import pyarrow as pa
   
   spark.createDataFrame(np.empty((0, 2))).dtypes
   spark.createDataFrame(pa.table({"a": pa.array([], pa.int64())})).dtypes
   ```
   
   Classic:
   ```
   [('_1', 'double'), ('_2', 'double')]
   [('a', 'bigint')]
   ```
   
   Connect:
   ```
   PySparkValueError: [CANNOT_INFER_EMPTY_SCHEMA] Can not infer schema from an 
empty dataset.
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. In Spark Connect, `createDataFrame` on an empty NumPy ndarray or empty 
PyArrow Table now returns an empty DataFrame with the same schema as classic 
PySpark, instead of raising an error.
   
   ### How was this patch tested?
   
   Added `test_createDataFrame_with_empty_ndarray` and 
`test_createDataFrame_with_empty_arrow_table` to `ArrowTestsMixin`, so they run 
for both classic (`ArrowTests`) and Spark Connect (`ArrowParityTests`).
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   


-- 
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]

Reply via email to