HyukjinKwon opened a new pull request, #464: URL: https://github.com/apache/spark-connect-rust/pull/464
### What changes were proposed in this pull request? [SPARK-61351](https://issues.apache.org/jira/browse/SPARK-61351): a pandas frame with nullable or Arrow-backed column labels is converted through Arrow, as PySpark converts it. - In `python/pyspark/sql/_pandas_input.py`, the new `_has_canonical_label_array` accepts more storages of an exact label `Index` on the Arrow routes of `createDataFrame`: - pandas' masked arrays: IntegerArray, FloatingArray and BooleanArray, over ndarrays `_data` and `_mask`; - the ArrowExtensionArray of any Arrow type, over a ChunkedArray `_pa_array`. - This follows SPARK-61314, which did the same for DatetimeIndex, TimedeltaIndex, PeriodIndex and IntervalIndex labels. - As for the string labels, the check makes sure reading the labels runs no user code: - the class must be pandas' own; - each hook that reading the labels reaches (`__iter__`, `__getitem__`, `__len__`, `__array__`, `__contains__`, `to_numpy`, `astype`, `isna`, `tolist`, `fillna`, `_hasna`, `dtype`) must be a function of pandas' own array modules, or the getter of a property or `cache_readonly`; - no instance attribute may shadow these hooks. - The existing recursion then covers MultiIndex levels and CategoricalIndex categories of these kinds. Sparse labels keep the row path. ### Why are the changes needed? Such labels come from a pivot, unstack or `.T` of nullable (`convert_dtypes()`) or Arrow-backed (`dtype_backend="pyarrow"`) data. These frames took the native row path, whose cells convert differently from PySpark 4.3.0's Arrow conversion: | Cell | Drop-in (row path) | PySpark | |---|---|---| | object column `[1, 2.5]` | "Type mismatch in row data" | double | | dict | map | struct | | NaN in a list | NaN | None | | `np.int32` | bigint | int | | `Decimal` in a list | `decimal(38,1)` | `decimal(2,1)` | | naive datetime | timestamp | timestamp_ntz | Also, under `spark.sql.session.timeZone=Asia/Seoul` with a client in Asia/Seoul, a datetime64 column under an Int64 label with an explicit `timestamp_ntz` schema read back `2020-01-01 18:00`; PySpark reads `2020-01-02 03:00`. ### Does this PR introduce _any_ user-facing change? Yes, in the Python client: these frames convert as in PySpark. ### How was this patch tested? - Offline (`python/tests/test_dropin_offline.py`), next to the datetime-like label tests of SPARK-61314: - `test_nullable_and_arrow_labels_convert_cells_as_pyspark` has 35 cases. It covers Int64, Float64, boolean, `int64[pyarrow]` and `timestamp[pyarrow]` labels, a MultiIndex level and a CategoricalIndex of Int64. Each runs with the mixed int/float, naive datetime list, dict, NaN-in-list and `np.int32` cells, and gets PySpark's Arrow types and values. All fail without the change. - `test_label_arrays_with_a_hook_of_their_own_keep_the_row_path`: a label array whose instance shadows a hook keeps the row path. - Live (`python/tests/test_dropin_e2e.py`): `test_create_dataframe_of_nullable_labels_keeps_ntz_values_as_pyspark`, for the NTZ case above. It fails without the change. - The reviewer's probe against official PySpark 4.3.0 (TZ=Asia/Seoul): - before the change, 240 differing lines over 7 label kinds; - after it, only the 34 lines of Sparse labels, which keep the row path. - The pandas internals the check reads were checked in pandas 2.3.3 (installed) and in the pandas 3.1.0 sources. CI's coverage job installs pandas 3.1: the hooks are in the same modules, and `cache_readonly` has `fget`. - The offline Python suites and the live drop-in suites against a local Spark 4.3.0 server pass. No Rust code changes. ### 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]
