You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ru...@apache.org on 2025/01/24 00:18:13 UTC
(spark) branch master updated: [SPARK-50935][ML][PYTHON][CONNECT] Support DCT on connect
This is an automated email from the ASF dual-hosted git repository.
ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 2d74c3d9885a [SPARK-50935][ML][PYTHON][CONNECT] Support DCT on connect
2d74c3d9885a is described below
commit 2d74c3d9885a4c5b238bd291fa5110443384c2c4
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Fri Jan 24 08:17:58 2025 +0800
[SPARK-50935][ML][PYTHON][CONNECT] Support DCT on connect
### What changes were proposed in this pull request?
Support DCT on connect
### Why are the changes needed?
For feature parity
### Does this PR introduce _any_ user-facing change?
yes
### How was this patch tested?
added tests
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #49626 from zhengruifeng/ml_connect_dct.
Authored-by: Ruifeng Zheng <ru...@apache.org>
Signed-off-by: Ruifeng Zheng <ru...@apache.org>
---
.../services/org.apache.spark.ml.Transformer | 1 +
python/pyspark/ml/tests/test_feature.py | 29 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/mllib/src/main/resources/META-INF/services/org.apache.spark.ml.Transformer b/mllib/src/main/resources/META-INF/services/org.apache.spark.ml.Transformer
index 6b163bb9c022..5bbc18191e5c 100644
--- a/mllib/src/main/resources/META-INF/services/org.apache.spark.ml.Transformer
+++ b/mllib/src/main/resources/META-INF/services/org.apache.spark.ml.Transformer
@@ -18,6 +18,7 @@
# Spark Connect ML uses ServiceLoader to find out the supported Spark Ml non-model transformer.
# So register the supported transformer here if you're trying to add a new one.
########### Transformers
+org.apache.spark.ml.feature.DCT
org.apache.spark.ml.feature.VectorAssembler
org.apache.spark.ml.feature.Tokenizer
org.apache.spark.ml.feature.RegexTokenizer
diff --git a/python/pyspark/ml/tests/test_feature.py b/python/pyspark/ml/tests/test_feature.py
index 126e8245ae78..316afe39d3ac 100644
--- a/python/pyspark/ml/tests/test_feature.py
+++ b/python/pyspark/ml/tests/test_feature.py
@@ -23,6 +23,7 @@ from typing import List, Tuple, Any
import numpy as np
from pyspark.ml.feature import (
+ DCT,
Binarizer,
CountVectorizer,
CountVectorizerModel,
@@ -59,6 +60,34 @@ from pyspark.testing.mlutils import check_params, SparkSessionTestCase
class FeatureTestsMixin:
+ def test_dct(self):
+ df = self.spark.createDataFrame([(Vectors.dense([5.0, 8.0, 6.0]),)], ["vec"])
+ dct = DCT()
+ dct.setInverse(False)
+ dct.setInputCol("vec")
+ dct.setOutputCol("resultVec")
+
+ self.assertFalse(dct.getInverse())
+ self.assertEqual(dct.getInputCol(), "vec")
+ self.assertEqual(dct.getOutputCol(), "resultVec")
+
+ output = dct.transform(df)
+ self.assertEqual(output.columns, ["vec", "resultVec"])
+ self.assertEqual(output.count(), 1)
+ self.assertTrue(
+ np.allclose(
+ output.head().resultVec.toArray(),
+ [10.96965511, -0.70710678, -2.04124145],
+ atol=1e-4,
+ )
+ )
+
+ # save & load
+ with tempfile.TemporaryDirectory(prefix="dct") as d:
+ dct.write().overwrite().save(d)
+ dct2 = DCT.load(d)
+ self.assertEqual(str(dct), str(dct2))
+
def test_string_indexer(self):
df = (
self.spark.createDataFrame(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org