HyukjinKwon commented on code in PR #41606:
URL: https://github.com/apache/spark/pull/41606#discussion_r1250052785
##########
python/pyspark/testing/utils.py:
##########
@@ -209,3 +220,45 @@ def check_error(
self.assertEqual(
expected, actual, f"Expected message parameters was '{expected}',
got '{actual}'"
)
+
+
+def assertSparkSchemaEquality(
+ s1: Optional[Union[AtomicType, StructType, str, List[str], Tuple[str,
...]]],
+ s2: Optional[Union[AtomicType, StructType, str, List[str], Tuple[str,
...]]],
+):
+ if s1 != s2:
+ msg = "Schemas are different"
+ raise AssertionError(msg)
+
+
+def assertSparkDFEquality(
+ left: PySparkDataFrame, right: PySparkDataFrame,
+):
+ def assert_rows_equality(rows1, rows2):
+ if rows1 != rows2:
+ msg = "Dataframes are different"
+ raise AssertionError(msg)
+
+ left = left.sort(left.columns)
+ right = right.sort(right.columns)
+
+ assertSparkSchemaEquality(left.schema, right.schema)
+ assert_rows_equality(left.collect(), right.collect())
+
+
+def assertDFEquality(
+ left: Union[
+ PySparkDataFrame, Optional[Union[AtomicType, StructType, str,
List[str], Tuple[str, ...]]]
+ ],
+ right: Union[
+ PySparkDataFrame, Optional[Union[AtomicType, StructType, str,
List[str], Tuple[str, ...]]]
+ ],
+):
+
+ from pyspark.testing.pandasutils import assertPandasDFEquality
+
+ if isinstance(left, pd.DataFrame) and isinstance(right, pd.DataFrame):
+ assertPandasDFEquality(left, right)
+
+ elif isinstance(left, PySparkDataFrame) and isinstance(right,
PySparkDataFrame):
+ assertSparkDFEquality(left, right)
Review Comment:
`else`?
--
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]