Registry / testing / chispa

chispa

JSON →
library0.12.0pypypi✓ verified 28d ago

Chispa is a PySpark test helper library that provides fast and descriptive methods for comparing Spark DataFrames. It's designed to make writing high-quality PySpark unit tests easier by offering clear error messages when assertions fail. The library is currently at version 0.12.0 and is actively maintained with regular releases.

pip install chispa
INSTALL
IMPORT
SIG · CHISPA
C
chispa
testingpythonv0.12.0
Install
2.0s avg
Import
—
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 25.3MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.0s · import 0.000s · 26MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

assert_df_equality
✓ from chispa import assert_df_equality
✗ from chispa.dataframe_comparer import assert_df_equality

This quickstart demonstrates how to use `chispa.dataframe_comparer.assert_df_equality` to compare two PySpark DataFrames. It initializes a SparkSession, creates two DataFrames (one identical, one with a subtle difference), and then uses `assert_df_equality` to check their equivalence, showcasing both a passing and a failing scenario with Chispa's descriptive error messages.

import os from pyspark.sql import SparkSession from chispa.dataframe_comparer import assert_df_equality # Initialize SparkSession (for local testing, typically done in a pytest fixture) spark = SparkSession.builder.appName("ChispaQuickstart").getOrCreate() # Create an 'actual' DataFrame data_actual = [ ("john", 1), ("jane", 2), ("doe", 3) ] df_actual = spark.createDataFrame(data_actual, ["name", "id"]) # Create an 'expected' DataFrame (identical for a passing test) data_expected = [ ("john", 1), ("jane", 2), ("doe", 3) ] df_expected = spark.createDataFrame(data_expected, ["name", "id"]) # Assert equality - this test should pass try: assert_df_equality(df_actual, df_expected) print("Assertion Passed: df_actual and df_expected are equal.") except Exception as e: print(f"Assertion Failed: {e}") # Create a different 'expected' DataFrame to demonstrate a failing test data_expected_fail = [ ("john", 1), ("jane", 99), # Intentional difference ("doe", 3) ] df_expected_fail = spark.createDataFrame(data_expected_fail, ["name", "id"]) # Assert equality - this test should fail, showing descriptive error try: assert_df_equality(df_actual, df_expected_fail) print("Assertion Passed (unexpectedly): df_actual and df_expected_fail are equal.") except Exception as e: print(f"Assertion Failed (as expected): {e}") # Stop SparkSession spark.stop()
Debug
Known issues
breakingChispa versions prior to 0.12.0 may not be fully compatible with PySpark 4.x. Version 0.12.0 explicitly adds support for Spark 4.x, so users upgrading their PySpark environment should ensure they are on Chispa 0.12.0 or newer.
fix
Upgrade chispa to 0.12.0 or a later version: `pip install --upgrade chispa`
affects: <0.12.0
deprecatedThe internal `bcolors` utility module was removed in `v0.11.0`. While primarily an internal refactor, direct imports of `chispa.bcolors` will now fail.
fix
Remove any direct imports of `chispa.bcolors`. If custom console coloring is needed, use a dedicated library or Python's `colorama`.
affects: >=0.11.0
gotchaBy default, `assert_df_equality` performs a strict comparison, expecting identical schemas (including nullability and metadata), column order, and row order. Divergences in any of these aspects will cause an assertion failure unless corresponding `ignore_*` flags (e.g., `ignore_nullable`, `ignore_column_order`, `ignore_row_order`, `ignore_metadata`) are explicitly set to `True`.
fix
Review the specific comparison requirements. Use `ignore_nullable=True`, `ignore_metadata=True`, `ignore_column_order=True`, or `ignore_row_order=True` as appropriate for your test case. For floating-point comparisons, consider `assert_approx_df_equality` or the `precision` argument.
affects: All
gotchaPrior to `v0.11.1`, a bug existed in `assert_df_equality` where using both `ignore_columns` and `ignore_row_order` simultaneously could lead to incorrect DataFrame comparisons due to faulty row ordering logic. This was resolved in `v0.11.1`.
fix
Upgrade chispa to version 0.11.1 or newer to ensure correct behavior when combining `ignore_columns` and `ignore_row_order`.
affects: <0.11.1
Upgrade
Version history
0.12.0latest on PyPI · released Mar 24, 2026
Audit
Dependencies
pysparkoptionalChispa is a test helper for PySpark DataFrames; PySpark is required for its functionality but not a direct install_requires dependency.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
1
Resources
chispa — pip install chispa · libregistry