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 8d1ca4b58370 [SPARK-46504][PS][TESTS][FOLLOWUPS] Make `test_insert` 
more stable by sorting before comparison
8d1ca4b58370 is described below

commit 8d1ca4b58370f23a3ec435aca26bcff7409fdb79
Author: Ruifeng Zheng <ruife...@apache.org>
AuthorDate: Tue Dec 26 16:04:27 2023 +0800

    [SPARK-46504][PS][TESTS][FOLLOWUPS] Make `test_insert` more stable by 
sorting before comparison
    
    ### What changes were proposed in this pull request?
    Make `test_insert` more stable by sorting before comparison
    
    ### Why are the changes needed?
    this test may fail in some env
    
    ### Does this PR introduce _any_ user-facing change?
    no, test-only
    
    ### How was this patch tested?
    ci and manually check
    
    ### Was this patch authored or co-authored using generative AI tooling?
    no
    
    Closes #44492 from zhengruifeng/ps_test_index_insert_stable.
    
    Authored-by: Ruifeng Zheng <ruife...@apache.org>
    Signed-off-by: Ruifeng Zheng <ruife...@apache.org>
---
 python/pyspark/pandas/tests/indexes/test_insert.py | 50 +++++++++++++++++-----
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/python/pyspark/pandas/tests/indexes/test_insert.py 
b/python/pyspark/pandas/tests/indexes/test_insert.py
index 4bbdf0a5f050..9dfb87ff569d 100644
--- a/python/pyspark/pandas/tests/indexes/test_insert.py
+++ b/python/pyspark/pandas/tests/indexes/test_insert.py
@@ -34,8 +34,14 @@ class IndexesInsertMixin:
         # Integer
         pidx = pd.Index([1, 2, 3], name="Koalas")
         psidx = ps.from_pandas(pidx)
-        self.assert_eq(pidx.insert(1, 100), psidx.insert(1, 100))
-        self.assert_eq(pidx.insert(-1, 100), psidx.insert(-1, 100))
+        self.assert_eq(
+            pidx.insert(1, 100).sort_values(),
+            psidx.insert(1, 100).sort_values(),
+        )
+        self.assert_eq(
+            pidx.insert(-1, 100).sort_values(),
+            psidx.insert(-1, 100).sort_values(),
+        )
         err_msg = "index 100 is out of bounds for axis 0 with size 3"
         with self.assertRaisesRegex(IndexError, err_msg):
             psidx.insert(100, 100)
@@ -46,8 +52,14 @@ class IndexesInsertMixin:
         # Floating
         pidx = pd.Index([1.0, 2.0, 3.0], name="Koalas")
         psidx = ps.from_pandas(pidx)
-        self.assert_eq(pidx.insert(1, 100.0), psidx.insert(1, 100.0))
-        self.assert_eq(pidx.insert(-1, 100.0), psidx.insert(-1, 100.0))
+        self.assert_eq(
+            pidx.insert(1, 100.0).sort_values(),
+            psidx.insert(1, 100.0).sort_values(),
+        )
+        self.assert_eq(
+            pidx.insert(-1, 100.0).sort_values(),
+            psidx.insert(-1, 100.0).sort_values(),
+        )
         err_msg = "index 100 is out of bounds for axis 0 with size 3"
         with self.assertRaisesRegex(IndexError, err_msg):
             psidx.insert(100, 100)
@@ -58,8 +70,14 @@ class IndexesInsertMixin:
         # String
         pidx = pd.Index(["a", "b", "c"], name="Koalas")
         psidx = ps.from_pandas(pidx)
-        self.assert_eq(pidx.insert(1, "x"), psidx.insert(1, "x"))
-        self.assert_eq(pidx.insert(-1, "x"), psidx.insert(-1, "x"))
+        self.assert_eq(
+            pidx.insert(1, "x").sort_values(),
+            psidx.insert(1, "x").sort_values(),
+        )
+        self.assert_eq(
+            pidx.insert(-1, "x").sort_values(),
+            psidx.insert(-1, "x").sort_values(),
+        )
         err_msg = "index 100 is out of bounds for axis 0 with size 3"
         with self.assertRaisesRegex(IndexError, err_msg):
             psidx.insert(100, "x")
@@ -70,8 +88,14 @@ class IndexesInsertMixin:
         # Boolean
         pidx = pd.Index([True, False, True, False], name="Koalas")
         psidx = ps.from_pandas(pidx)
-        self.assert_eq(pidx.insert(1, True), psidx.insert(1, True))
-        self.assert_eq(pidx.insert(-1, True), psidx.insert(-1, True))
+        self.assert_eq(
+            pidx.insert(1, True).sort_values(),
+            psidx.insert(1, True).sort_values(),
+        )
+        self.assert_eq(
+            pidx.insert(-1, True).sort_values(),
+            psidx.insert(-1, True).sort_values(),
+        )
         err_msg = "index 100 is out of bounds for axis 0 with size 4"
         with self.assertRaisesRegex(IndexError, err_msg):
             psidx.insert(100, True)
@@ -84,8 +108,14 @@ class IndexesInsertMixin:
             [("a", "x"), ("b", "y"), ("c", "z")], names=["Hello", "Koalas"]
         )
         psmidx = ps.from_pandas(pmidx)
-        self.assert_eq(pmidx.insert(2, ("h", "j")), psmidx.insert(2, ("h", 
"j")))
-        self.assert_eq(pmidx.insert(-1, ("h", "j")), psmidx.insert(-1, ("h", 
"j")))
+        self.assert_eq(
+            pmidx.insert(2, ("h", "j")).sort_values(),
+            psmidx.insert(2, ("h", "j")).sort_values(),
+        )
+        self.assert_eq(
+            pmidx.insert(-1, ("h", "j")).sort_values(),
+            psmidx.insert(-1, ("h", "j")).sort_values(),
+        )
 
         err_msg = "index 4 is out of bounds for axis 0 with size 3"
         with self.assertRaisesRegex(IndexError, err_msg):


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

Reply via email to