[SPARK-54090][PYTHON] Fix cascading diff in assertDataFrameEqual when row counts differ#55522
Closed
Yicong-Huang wants to merge 1 commit into
Closed
[SPARK-54090][PYTHON] Fix cascading diff in assertDataFrameEqual when row counts differ#55522Yicong-Huang wants to merge 1 commit into
Yicong-Huang wants to merge 1 commit into
Conversation
Contributor
Author
HyukjinKwon
approved these changes
Apr 24, 2026
Member
|
Merged to master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
When
assertDataFrameEqualis called withcheckRowOrder=False(the default) and the two inputs have different row counts, a single missing/extra row cascades into a mismatch on every subsequent row. This inflates both the diff count and the reported mismatch percentage.Root cause: after sorting both lists by
str(row),assert_rows_equalpairs rows withzip_longest. When one side is shorter, the pairing shifts past every row following the hole.Fix: switch to a merge-walk over the sorted lists only when their lengths differ. Equal lengths keep
zip_longestso that field-level diffs continue to be reported as paired rows (preserving existing docstrings and tests that rely on "B vs X" style pairing).The merge-walk uses
compare_rowsfor equality (honoringrtol/atol) andstr(r)for ordering decisions (consistent with how the lists were sorted).Why are the changes needed?
Reproducer:
Before this fix:
Results do not match: ( 60.00000 % )(3 of 5 rows reported as different).After this fix:
Results do not match: ( 20.00000 % )(onlyRow(id='3')is reported).A larger example from the JIRA: rows1 has 5 rows, rows2 has 3 of them missing in the middle -- the old code reports 80% mismatch; the new code reports 40%, matching what a user would expect from a sorted-set comparison.
Does this PR introduce any user-facing change?
Yes, but only in the error message / reported data when
assertDataFrameEqual(checkRowOrder=False)is given inputs whose row counts differ:includeDiffRows=Truenow returns(row, None)tuples for extras and(None, row)tuples for missing rows, rather than shifted(row, row)pairs.Behavior when row counts are equal (including all existing docstring examples) is unchanged.
How was this patch tested?
python/pyspark/sql/tests/test_utils.py:test_different_row_count_middle_missing_no_cascading_difftest_different_row_count_multiple_missingtest_different_row_count_includeDiffRowstest_different_row_count_mixed_extra_and_missingtest_different_row_count_extras_at_endWas this patch authored or co-authored using generative AI tooling?
No.