@@ -1884,6 +1884,32 @@ def test_assert_schema_equal_with_timestamp_nanos_types(self):
18841884 assertSchemaEqual (s1 , StructType ([StructField ("ts" , TimestampNTZNanosType (7 ), True )]))
18851885
18861886
1887+ class RowComparisonTests (unittest .TestCase ):
1888+ def test_different_row_lengths (self ):
1889+ pairs = [(Row (), Row (x = 1 )), (Row (x = 1 ), Row (x = 1 , y = 2 ))]
1890+ for left , right in pairs :
1891+ for actual , expected in [(left , right ), (right , left )]:
1892+ for wrap in [
1893+ lambda row : row ,
1894+ lambda row : Row (nested = row ),
1895+ lambda row : Row (items = [row ]),
1896+ lambda row : Row (mapping = {"key" : row }),
1897+ ]:
1898+ for ordered in [False , True ]:
1899+ with self .subTest (actual = actual , expected = expected , ordered = ordered ):
1900+ with self .assertRaises (PySparkAssertionError ) as error :
1901+ assertDataFrameEqual (
1902+ [wrap (actual )], [wrap (expected )], checkRowOrder = ordered
1903+ )
1904+ self .assertEqual (error .exception .getCondition (), "DIFFERENT_ROWS" )
1905+
1906+ def test_equal_row_lengths (self ):
1907+ for row in [Row (), Row (x = 1 ), Row (nested = Row (x = 1 , y = 2 ))]:
1908+ assertDataFrameEqual ([row ], [row ])
1909+ with self .assertRaises (PySparkAssertionError ):
1910+ assertDataFrameEqual ([Row (x = 1 )], [Row (x = 2 )])
1911+
1912+
18871913class UtilsTests (UtilsTestsMixin , ReusedSQLTestCase ):
18881914 pass
18891915
0 commit comments