ueshin commented on code in PR #47884:
URL: https://github.com/apache/spark/pull/47884#discussion_r1735195883


##########
python/pyspark/sql/tests/test_dataframe.py:
##########
@@ -957,6 +957,66 @@ def test_checkpoint_dataframe(self):
             self.spark.range(1).localCheckpoint().explain()
             self.assertIn("ExistingRDD", buf.getvalue())
 
+    def test_transpose(self):
+        df = self.spark.createDataFrame([{"a": "x", "b": "y", "c": "z"}])
+
+        # default index column
+        transposed_df = df.transpose()
+        expected_schema = StructType(
+            [StructField("key", StringType(), False), StructField("x", 
StringType(), True)]
+        )
+        expected_data = [Row(key="b", x="y"), Row(key="c", x="z")]
+        self.assertEqual(transposed_df.schema, expected_schema)
+        self.assertEqual(transposed_df.collect(), expected_data)
+
+        # specified index column
+        transposed_df = df.transpose("c")
+        expected_schema = StructType(
+            [StructField("key", StringType(), False), StructField("z", 
StringType(), True)]
+        )
+        expected_data = [Row(key="a", z="x"), Row(key="b", z="y")]
+        self.assertEqual(transposed_df.schema, expected_schema)
+        self.assertEqual(transposed_df.collect(), expected_data)
+
+        # enforce transpose max values
+        with self.sql_conf({"spark.sql.transposeMaxValues": 0}):
+            with self.assertRaisesRegex(
+                AnalysisException,
+                r"\[EXCEED_ROW_LIMIT\] Number of rows exceeds the allowed 
limit of",
+            ):
+                df.transpose().collect()

Review Comment:
   We should use `check_error`?



##########
python/pyspark/sql/tests/test_dataframe.py:
##########
@@ -957,6 +957,66 @@ def test_checkpoint_dataframe(self):
             self.spark.range(1).localCheckpoint().explain()
             self.assertIn("ExistingRDD", buf.getvalue())
 
+    def test_transpose(self):
+        df = self.spark.createDataFrame([{"a": "x", "b": "y", "c": "z"}])
+
+        # default index column
+        transposed_df = df.transpose()
+        expected_schema = StructType(
+            [StructField("key", StringType(), False), StructField("x", 
StringType(), True)]
+        )
+        expected_data = [Row(key="b", x="y"), Row(key="c", x="z")]
+        self.assertEqual(transposed_df.schema, expected_schema)
+        self.assertEqual(transposed_df.collect(), expected_data)

Review Comment:
   We should use `assertDataFrameEqual`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to