HyukjinKwon opened a new pull request, #177: URL: https://github.com/apache/spark-connect-rust/pull/177
### What changes were proposed in this pull request? [SPARK-60954](https://issues.apache.org/jira/browse/SPARK-60954): `createDataFrame` of a pandas DataFrame now types these columns as PySpark's Arrow conversion does, and the Arrow encoder rejects a null map key with an error. - **A column without values** (all NaN, NaT or None) takes the type of its dtype, as `pa.Schema.from_pandas` gives it: - `double` or `float` for floats; - `timestamp` for datetimes; - the integer, boolean or string type of a nullable dtype; - `void` for an object column. - **A column of Decimals** takes the precision and scale that Arrow infers from all its values: the most integer digits and the largest scale. For example, `1.5` and `2.25` give `decimal(3,2)`. - **Decimal strings:** a Decimal is now written without an exponent, so a value such as `Decimal("1E+2")` encodes. - **Null map keys:** - A pandas column with a map of a null key raises PySpark's `PySparkTypeError`: `Exception thrown when converting pandas.Series (object) with name '<column>' to Arrow Array (None).` - In the Rust encoder, a null map key is an error, and the map arrays are built with `try_new`, so that `SparkSession::create_dataframe` cannot panic on one. Other pandas columns are still typed by their first non-null value. ### Why are the changes needed? Every column was typed by its first non-null value: - `pd.DataFrame({"id": [1, 2], "s": [np.nan, np.nan]})` raised `CANNOT_DETERMINE_TYPE`, where PySpark gives a `double` column, and before #149 this worked too. - A column of `Decimal("1.5")` and `Decimal("2.25")` became `decimal(38,1)`, and `2.25` was silently stored as `2.2`. A Decimal written with an exponent failed to encode. - A dict with a `None` key panicked in Rust (`PanicException`), which `except Exception` does not catch. ### Does this PR introduce _any_ user-facing change? Yes, these pandas columns convert as in PySpark 4.3.0. ### How was this patch tested? - Against a local Spark 4.3.0 server, a probe of seven pandas inputs gives output identical to official PySpark 4.3.0: - all-NaN, all-None and all-NaT columns; - Decimals of different scales, with an exponent and with None; - a map with a None key. - A new unit test checks that a null map key is an error of the encoder. - A new offline test checks the columns without values and the error. - A new live test checks the types and values, and it also passes with official PySpark 4.3.0. - The lib tests and every integration test, e2e included, against the local server (644 passed), the build of all tests with `wasm-udf`, the offline Python suites (614 passed, 8 live cases skipped), and the live drop-in and Arrow suites (58 passed) and live cases (10 passed). 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]
