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/02/04 09:41:08 UTC

(spark) branch branch-4.0 updated: [SPARK-51078][SPARK-50963][ML][PYTHON][CONNECT] Fix the py4j call in `StopWordsRemover`

This is an automated email from the ASF dual-hosted git repository.

ruifengz pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 449199186de8 [SPARK-51078][SPARK-50963][ML][PYTHON][CONNECT] Fix the py4j call in `StopWordsRemover`
449199186de8 is described below

commit 449199186de8ec41cc9db43b00ef212d8cff45db
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Tue Feb 4 17:40:40 2025 +0800

    [SPARK-51078][SPARK-50963][ML][PYTHON][CONNECT] Fix the py4j call in `StopWordsRemover`
    
    ### What changes were proposed in this pull request?
    Fix the py4j call in `StopWordsRemover`
    
    ### Why are the changes needed?
    to enable `StopWordsRemover`
    
    ### Does this PR introduce _any_ user-facing change?
    yes
    
    ### How was this patch tested?
    reenabled tests
    
    ### Was this patch authored or co-authored using generative AI tooling?
    no
    
    Closes #49789 from zhengruifeng/mlc_rm_fix.
    
    Lead-authored-by: Ruifeng Zheng <ru...@apache.org>
    Co-authored-by: Hyukjin Kwon <gu...@gmail.com>
    Signed-off-by: Ruifeng Zheng <ru...@apache.org>
    (cherry picked from commit e0a7db2d2a7d295f933f9fc2d5605c5e59c58aa7)
    Signed-off-by: Ruifeng Zheng <ru...@apache.org>
---
 python/pyspark/ml/feature.py                           | 8 ++++----
 python/pyspark/ml/tests/connect/test_parity_feature.py | 8 --------
 python/pyspark/ml/tests/test_feature.py                | 2 --
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/python/pyspark/ml/feature.py b/python/pyspark/ml/feature.py
index d7754367015f..20eadb326b63 100755
--- a/python/pyspark/ml/feature.py
+++ b/python/pyspark/ml/feature.py
@@ -4992,7 +4992,7 @@ class StopWordsRemover(
     Notes
     -----
     - null values from input array are preserved unless adding null to stopWords explicitly.
-    - In Spark Connect Mode, the default value of parameter `locale` is not set.
+    - In Spark Connect Mode, the default value of parameter `locale` and `stopWords` are not set.
 
     Examples
     --------
@@ -5092,10 +5092,10 @@ class StopWordsRemover(
             "org.apache.spark.ml.feature.StopWordsRemover", self.uid
         )
         if isinstance(self._java_obj, str):
-            # Skip setting the default value of 'locale', which needs to invoke a JVM method.
-            # So if users don't explicitly set 'locale', then getLocale fails.
+            # Skip setting the default value of 'locale' and 'stopWords', which
+            # needs to invoke a JVM method.
+            # So if users don't explicitly set 'locale' and/or 'stopWords', then the getters fails.
             self._setDefault(
-                stopWords=StopWordsRemover.loadDefaultStopWords("english"),
                 caseSensitive=False,
             )
         else:
diff --git a/python/pyspark/ml/tests/connect/test_parity_feature.py b/python/pyspark/ml/tests/connect/test_parity_feature.py
index e0a6a0141b57..d75146be41cf 100644
--- a/python/pyspark/ml/tests/connect/test_parity_feature.py
+++ b/python/pyspark/ml/tests/connect/test_parity_feature.py
@@ -30,14 +30,6 @@ class FeatureParityTests(FeatureTestsMixin, ReusedConnectTestCase):
     def test_string_indexer_from_labels(self):
         super().test_string_indexer_from_labels()
 
-    @unittest.skip("Need to support.")
-    def test_stop_words_remover(self):
-        super().test_stop_words_remover()
-
-    @unittest.skip("Need to support.")
-    def test_stop_words_remover_II(self):
-        super().test_stop_words_remover_II()
-
 
 if __name__ == "__main__":
     from pyspark.ml.tests.connect.test_parity_feature import *  # noqa: F401
diff --git a/python/pyspark/ml/tests/test_feature.py b/python/pyspark/ml/tests/test_feature.py
index 068ce8f5bb6d..edfda54ca83c 100644
--- a/python/pyspark/ml/tests/test_feature.py
+++ b/python/pyspark/ml/tests/test_feature.py
@@ -889,8 +889,6 @@ class FeatureTestsMixin:
         self.assertEqual(stopWordRemover.getInputCol(), "input")
         transformedDF = stopWordRemover.transform(dataset)
         self.assertEqual(transformedDF.head().output, ["panda"])
-        self.assertEqual(type(stopWordRemover.getStopWords()), list)
-        self.assertTrue(isinstance(stopWordRemover.getStopWords()[0], str))
         # Custom
         stopwords = ["panda"]
         stopWordRemover.setStopWords(stopwords)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org