A data engineering team is writing unit tests for a PySpark transformation function that filters and aggregates a sales DataFrame. They want to assert that two DataFrames are equal regardless of row order. Which library provides a purpose-built assertion function for this use case in PySpark unit tests?
- A. pytest-spark, using the
assert_frame_equalhelper - B. unittest, using the built-in
assertEqualmethod on the DataFrame's.collect()result after sorting - C. Chispa, using the
assert_df_equalityfunction withignore_row_order=True✓ Correct - D. pandas-testing, by converting both DataFrames with
.toPandas()and callingpd.testing.assert_frame_equal
Explanation
Chispa is a PySpark-specific testing library that provides assert_df_equality, which natively handles row-order independence, schema comparison, and null semantics — exactly what is needed for DataFrame assertions. pytest-spark does not provide an assert_frame_equal helper. Converting to pandas with .toPandas() works in small tests but does not scale and is not order-agnostic by default. Using unittest.assertEqual on .collect() results is fragile because list equality is order-sensitive, and manually sorting adds complexity without a guarantee of correctness across all data types.