HyukjinKwon opened a new pull request, #660: URL: https://github.com/apache/spark-connect-rust/pull/660
### What changes were proposed in this pull request? A follow-up of SPARK-61630 (#643), from the r13 post-merge review (found by spark-76). `pyspark.ml` sends the dataset of four methods as an argument of a helper or attribute call: - `PowerIterationClustering.assignClusters`; - `PrefixSpan.findFrequentSequentialPatterns`; - `ALSModel.recommendForUserSubset` and `recommendForItemSubset`. The serialization of that call (`pyspark.ml.connect.serialize.serialize`) sends a value that is not a DataFrame as a literal: - a `(value, DataType)` pair as a literal of that type; - an ML vector or matrix as itself; - anything else as the literal of `LiteralExpression._from_value`, which raises PySpark's error for a value that cannot be one. So, as of official pyspark-client 4.3.0: - a pandas DataFrame raises ``[UNSUPPORTED_DATA_TYPE] Unsupported DataType `DataFrame`.``; - an empty list raises `CANNOT_INFER_ARRAY_ELEMENT_TYPE`; - a NumPy array, a dict or a tuple raises `UNSUPPORTED_DATA_TYPE`. The native `helper_dataset_of` of these methods now follows that serialization: an unconvertible value goes through the client's `to_value_column`, which matches `_from_value`, as `Column.otherwise` does. - **Before:** a pandas DataFrame raised the plain `TypeError` of a native fit (`... requires a Spark DataFrame; pandas DataFrames are not supported ...`), and lists and arrays were taken as `lit` takes them. - **Now:** these four methods raise PySpark's error of the conversion, before any request. A value that PySpark sends for the server to reject still raises the `TypeError` of #643 (`takes a Spark DataFrame, not '...'`); that now includes the vectors, matrices and typed pairs that PySpark sends as they are. A fit, transform or evaluate still raises the pandas `TypeError` of SPARK-61629: there, the reference raises an `AttributeError` of `sparkSession` instead of a PySpark error. ### Why are the changes needed? To raise the errors that `pyspark.ml` raises over Spark Connect for these methods. ### Does this PR introduce _any_ user-facing change? Yes, in the Python client. For the four helper methods above: - a pandas DataFrame, an empty list, a NumPy array, a dict or a tuple raises PySpark's `UNSUPPORTED_DATA_TYPE` or `CANNOT_INFER_ARRAY_ELEMENT_TYPE`, where it raised a `TypeError`; - an ML vector or matrix, or a `(value, DataType)` pair, raises the `TypeError`, where it raised `UNSUPPORTED_DATA_TYPE`. ### How was this patch tested? - Offline parity cases for all four methods, covering the outcomes of 18 inputs of official pyspark-client 4.3.0's `LiteralExpression._from_value` (`to_value_column` matches it on all 18). The pandas tests of `test_ml_offline.py`, `test_als_offline.py` and `test_frequent_patterns_offline.py` now expect PySpark's `UNSUPPORTED_DATA_TYPE` for the helper calls. These tests fail without the change. - The ML offline suites, including `test_frequent_patterns_offline.py` and `test_als_offline.py`, and the ML e2e files of these methods, against a Spark 4.3.0 server. - clippy with `-D warnings` on Rust 1.100.0, `cargo fmt --all --check`, and ruff. ### 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]
