This is an automated email from the ASF dual-hosted git repository.

ruifengz 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 91ca9cb89b59 [SPARK-54493][PYTHON] Fix assertSchemaEqual for MapType
91ca9cb89b59 is described below

commit 91ca9cb89b59376137c94e948be71bb024f6519b
Author: Tian Gao <[email protected]>
AuthorDate: Wed Nov 26 11:25:22 2025 +0800

    [SPARK-54493][PYTHON] Fix assertSchemaEqual for MapType
    
    ### What changes were proposed in this pull request?
    
    Deal with `MapType` in 
`assertSchemaEqual.compare_datatypes_ignore_nullable`.
    
    ### Why are the changes needed?
    
    Otherwise all `MapType` will be considered equal when `ignore_nullable == 
True`
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    A regression test is added
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #53216 from gaogaotiantian/fix-assert-schema-equal.
    
    Authored-by: Tian Gao <[email protected]>
    Signed-off-by: Ruifeng Zheng <[email protected]>
---
 python/pyspark/sql/tests/test_utils.py | 7 +++++++
 python/pyspark/testing/utils.py        | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/python/pyspark/sql/tests/test_utils.py 
b/python/pyspark/sql/tests/test_utils.py
index 9ec977c2552e..08d360a19e81 100644
--- a/python/pyspark/sql/tests/test_utils.py
+++ b/python/pyspark/sql/tests/test_utils.py
@@ -1264,6 +1264,13 @@ class UtilsTestsMixin:
 
         assertSchemaEqual(s1, s2)
 
+    def test_schema_ignore_nullable_map_unequal(self):
+        s1 = StructType([StructField("m", MapType(StringType(), 
IntegerType()), True)])
+        s2 = StructType([StructField("m", MapType(IntegerType(), 
StringType()), True)])
+
+        with self.assertRaises(PySparkAssertionError):
+            assertSchemaEqual(s1, s2, ignoreNullable=True)
+
     def test_schema_ignore_nullable_struct_equal(self):
         s1 = StructType(
             [StructField("names", StructType([StructField("age", 
IntegerType(), True)]), True)]
diff --git a/python/pyspark/testing/utils.py b/python/pyspark/testing/utils.py
index 2c13d2f74026..4ea3dbf30178 100644
--- a/python/pyspark/testing/utils.py
+++ b/python/pyspark/testing/utils.py
@@ -592,6 +592,10 @@ def assertSchemaEqual(
         if dt1.typeName() == dt2.typeName():
             if dt1.typeName() == "array":
                 return compare_datatypes_ignore_nullable(dt1.elementType, 
dt2.elementType)
+            elif dt1.typeName() == "map":
+                return compare_datatypes_ignore_nullable(
+                    dt1.keyType, dt2.keyType
+                ) and compare_datatypes_ignore_nullable(dt1.valueType, 
dt2.valueType)
             elif dt1.typeName() == "decimal":
                 # Fix for SPARK-51062: Compare precision and scale for decimal 
types
                 return dt1.precision == dt2.precision and dt1.scale == 
dt2.scale


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

Reply via email to