HyukjinKwon opened a new pull request, #406:
URL: https://github.com/apache/spark-connect-rust/pull/406

   ### What changes were proposed in this pull request?
   
   [SPARK-61227](https://issues.apache.org/jira/browse/SPARK-61227): Convert a 
pandas frame with default column labels through Arrow, as PySpark does.
   
   `_has_canonical_columns` in `python/pyspark/sql/_pandas_input.py` accepts a 
default `pd.RangeIndex` of column labels, so the Arrow routes of 
`createDataFrame` (explicit struct schema, names or inferred schema, and the 
generic explicit route) take a plain frame whose labels are the default ones. 
The check for a RangeIndex has the same override rules as the check for an 
`Index`: the exact type, no override of `__getattribute__`, `__iter__` or 
`__len__` on the class or the instance, a pandas-defined iteration and length, 
and a plain `range` as the label storage. Subclasses and instance overrides 
keep the row path.
   
   Official PySpark 4.3.0 converts these frames with Arrow. Across a matrix of 
RangeIndex frames (numeric frames with NaN under int, long and double schemas, 
object columns of Rows, dicts with and without 
`spark.sql.execution.pandas.inferPandasDictAsMap`, lists of naive datetimes and 
Decimals, strings, timestamps with time zones, empty frames, names lists and 
DDL schemas, and Arrow on and off), the results and errors now match official 
PySpark 4.3.0. The Rows under non-struct schemas, the dict cells and the list 
cells, which the row path converted differently, follow the Arrow conversion 
too for these frames.
   
   ### Why are the changes needed?
   
   `pd.DataFrame([[None], [3]])` and `pd.DataFrame(ndarray)` have default 
column labels, a RangeIndex, which the Arrow routes did not accept, so they 
took the native row path. There `spark.createDataFrame(pd.DataFrame([[None], 
[3]]), "x int")` raised `PySparkRuntimeError: Type mismatch in row data`, while 
PySpark 4.3.0 returns `[Row(x=None), Row(x=3)]`. The same frame with named or 
integer labels already worked.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A pandas frame with default column labels now converts with Arrow under 
an explicit schema, as PySpark does, instead of failing or converting 
differently on the row path. Customized (subclassed) frames and frames with 
other labels are unchanged.
   
   Two existing tests in `test_dropin_offline.py` pinned the row path for these 
frames. `test_container_input_values_and_errors` and 
`test_container_input_subclass_numeric_precedence` now expect the Arrow 
conversion errors (`PySparkValueError`, "Exception thrown when converting 
pandas.Series") that official PySpark 4.3.0 raises for the same frames.
   
   ### How was this patch tested?
   
   - `test_default_range_index_frame_takes_arrow_route` (offline): the NaN of a 
float column under `x int`, `x long` and `a int, b int` converts to nulls, not 
a row-path error.
   - `test_default_range_index_labels_keep_row_path_for_overrides` (offline): 
the label check accepts a default RangeIndex and declines a subclass, an 
instance `__iter__` override and a class `__len__` override.
   - `test_default_range_index_pandas_frames_convert_as_pyspark` (live): six 
frames (NaN under int, Rows under an array schema, dicts, lists of naive 
datetimes and Decimals) give the schemas and values of PySpark 4.3.0.
   - The existing tests `test_container_input_values_and_errors` and 
`test_container_input_subclass_numeric_precedence` are updated as described 
above.
   - The lib tests of both crates (658 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2811 passed, 8 skipped), and the 
live drop-in and Arrow suites (230 passed) and live cases (12 passed) against a 
local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


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