Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-46504][PS][TESTS][FOLLOWUPS] Make test_insert more stable by sorting before comparison #44492

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions python/pyspark/pandas/tests/indexes/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ def test_insert(self):
# 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)
Expand All @@ -46,8 +52,14 @@ def test_insert(self):
# 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)
Expand All @@ -58,8 +70,14 @@ def test_insert(self):
# 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")
Expand All @@ -70,8 +88,14 @@ def test_insert(self):
# 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)
Expand All @@ -84,8 +108,14 @@ def test_insert(self):
[("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):
Expand Down