HyukjinKwon commented on code in PR #41606:
URL: https://github.com/apache/spark/pull/41606#discussion_r1252651645


##########
python/pyspark/testing/utils.py:
##########
@@ -209,3 +234,70 @@ def check_error(
         self.assertEqual(
             expected, actual, f"Expected message parameters was '{expected}', 
got '{actual}'"
         )
+
+
+def assertSchemaEqual(
+    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 assertDataFrameEqual(
+    df: DataFrame, expected: Union[DataFrame, List[Row]], ignore_row_order: 
bool = True
+):
+    if df is None and expected is None:
+        return True
+    elif df is None or expected is None:
+        return False
+
+    def compare(r1: Row, r2: Row):
+        if r1 is None and r2 is None:
+            return True
+        elif r1 is None or r2 is None:
+            return False
+
+        d1 = r1.asDict()
+        d2 = r2.asDict()
+
+        for key in d1.keys() & d2.keys():
+            if isinstance(d1[key], float) and isinstance(d2[key], float):
+                if abs(d1[key] - d2[key]) > 1e-5:
+                    return False
+            else:
+                if d1[key] != d2[key]:
+                    return False
+        return True
+
+    def assert_rows_equal(rows1: Row, rows2: Row):
+        zipped = list(zip_longest(rows1, rows2))

Review Comment:
   Ah, I see. Alright that's fine. You should probably also think about 
leveraging a method like https://docs.python.org/3/library/difflib.html



-- 
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