This is an automated email from the ASF dual-hosted git repository.
gurwls223 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 f54aee14cef [SPARK-38971][PYTHON][TESTS] Test anchor frame for
in-place `Series.rename_axis`
f54aee14cef is described below
commit f54aee14cefb039b41e921e670b6c463ccb6ef53
Author: Xinrong Meng <[email protected]>
AuthorDate: Thu Apr 21 09:22:38 2022 +0900
[SPARK-38971][PYTHON][TESTS] Test anchor frame for in-place
`Series.rename_axis`
### What changes were proposed in this pull request?
Test anchor frame for in-place `Series.rename_axis`.
### Why are the changes needed?
As a follow-up for https://github.com/apache/spark/pull/36250, we should
ensure the in-place `rename_axis` on Series doesn't change its anchor frame.
### Does this PR introduce _any_ user-facing change?
No. Test only.
### How was this patch tested?
Unit test.
Closes #36269 from xinrong-databricks/series.rename_axis.
Authored-by: Xinrong Meng <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
python/pyspark/pandas/tests/test_series.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/python/pyspark/pandas/tests/test_series.py
b/python/pyspark/pandas/tests/test_series.py
index 4baa9861ac1..7ae4e1da6d3 100644
--- a/python/pyspark/pandas/tests/test_series.py
+++ b/python/pyspark/pandas/tests/test_series.py
@@ -228,8 +228,9 @@ class SeriesTest(PandasOnSparkTestCase, SQLTestUtils):
def test_rename_axis(self):
index = pd.Index(["A", "B", "C"], name="index")
- pser = pd.Series([1.0, 2.0, 3.0], index=index, name="name")
- psser = ps.from_pandas(pser)
+ pdf = pd.DataFrame({"x": [1.0, 2.0, 3.0]}, index=index)
+ psdf = ps.from_pandas(pdf)
+ pser, psser = pdf.x, psdf.x
self.assert_eq(
pser.rename_axis("index2").sort_index(),
@@ -241,12 +242,6 @@ class SeriesTest(PandasOnSparkTestCase, SQLTestUtils):
(psser + 1).rename_axis("index2").sort_index(),
)
- pser2 = pser.copy()
- psser2 = psser.copy()
- pser2.rename_axis("index2", inplace=True)
- psser2.rename_axis("index2", inplace=True)
- self.assert_eq(pser2.sort_index(), psser2.sort_index())
-
self.assertRaises(ValueError, lambda: psser.rename_axis(["index2",
"index3"]))
self.assertRaises(TypeError, lambda:
psser.rename_axis(mapper=["index2"], index=["index3"]))
@@ -260,6 +255,12 @@ class SeriesTest(PandasOnSparkTestCase, SQLTestUtils):
psser.rename_axis(index=str.upper).sort_index(),
)
+ pser.rename_axis("index2", inplace=True)
+ psser.rename_axis("index2", inplace=True)
+ self.assert_eq(pser.sort_index(), psser.sort_index())
+ # Note: in pandas, pdf.x's index is renamed, whereas pdf's index isn't
due to a bug.
+ self.assert_eq(pdf, psdf)
+
index = pd.MultiIndex.from_tuples(
[("A", "B"), ("C", "D"), ("E", "F")], names=["index1", "index2"]
)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]