pyspark-regression
pyspark-regression is a concise, no-nonsense library for regression testing between PySpark Dataframes.
For install instructions and API documentation, please visit https://forrest-bajbek.github.io/pyspark-regression/
What is a Regression Test?
A Regression Test ensures that changes to code only produce expected outcomes, introducing no new bugs. These tests are particularly challenging when working with database tables, as the result can be too large to visually inspect. When updating a SQL transformation, Data Engineers must ensure that no rows or columns were unintentionally altered, even if the table has hundreds columns and billions of rows.
pyspark-regression reduces the complexity of Regression Testing by implementing a clean Python API for running regression tests between DataFrames in Apache Spark.
Example
Consider the following table:
| id | name | price |
|---|---|---|
| 1 | Taco | 3.001 |
| 2 | Burrito | 6.50 |
| 3 | flauta | 7.50 |
Imagine you are a Data Engineer, and you want to change the underlying ETL so that:
- The price for Tacos is rounded to 2 decimal places.
- The name for Flautas is capitalized.
You make your changes, and the new table looks like this:
| id | name | price |
|---|---|---|
| 1 | Taco | 3.00 |
| 2 | Burrito | 6.50 |
| 3 | Flauta | 7.50 |
Running a regression test will help you confirm that the new ETL changed the data how you expected.
Let's create the old and new tables as dataframes so we can run a Regression Test:
from pyspark.sql import SparkSession
from pyspark.sql.types import *
from pyspark_regression import RegressionTest
spark = SparkSession.builder.getOrCreate()
spark.conf.set("spark.sql.shuffle.partitions", 1)
schema = StructType(
[
StructField("id", IntegerType()),
StructField("name", StringType()),
StructField("price", DoubleType()),
]
)
# The old data
df_old = spark.createDataFrame(
[
(1, 'Taco', 3.001),
(2, 'Burrito', 6.50),
(3, 'flauta', 7.50),
],
schema=schema
)
# The new data
df_new = spark.createDataFrame(
[
(1, 'Taco', 3.00), # Corrected price
(2, 'Burrito', 6.50),
(3, 'Flauta', 7.50), # Corrected name
],
schema=schema
)
regression_test = RegressionTest(
df_old=df_old,
df_new=df_new,
pk='id',
)
RegressionTest() returns a Python class with properties that let you inspect the differences between dataframes. Most notably, the summary property prints a comprehensive analysis in Markdown.
>>> print(regression_test.summary)
# Regression Test: df
- run_id: de9bd4eb-5313-4057-badc-7322ee23b83b
- run_time: 2022-05-25 08:53:50.581283
## Result: **FAILURE**.
Printing Regression Report...
### Table stats
- Count records in old df: 3
- Count records in new df: 3
- Count pks in old df: 3
- Count pks in new df: 3
### Diffs
- Columns with diffs: {'name', 'price'}
- Number of records with diffs: 2 (%oT: 66.7%)
Diff Summary:
| column_name | data_type | diff_category | count_record | count_record_%oT |
|:--------------|:------------|:---------------------|---------------:|:-------------------|
| name | string | capitalization added | 1 | 33.3% |
| price | double | rounding | 1 | 33.3% |
Diff Samples: (5 samples per column_name, per diff_category, per is_duplicate)
| column_name | data_type | pk | old_value | new_value | diff_category |
|:--------------|:------------|-----:|:------------|:------------|:---------------------|
| name | string | 3 | 'flauta' | 'Flauta' | capitalization added |
| price | double | 1 | 3.001 | 3.0 | rounding |
The RegressionTest class provides low level access to all the methods used to build the summary:
>>> print(regression_test.count_record_old) # count of records in df_old
3
>>> print(regression_test.count_record_new) # count of records in df_new
3
>>> print(regression_test.columns_diff) # Columns with diffs
{'name', 'price'}
>>> regression_test.df_diff.filter("column_name = 'price'").show() # Show all diffs for 'price' column
+-----------+---------+---+---------+---------+-------------+
|column_name|data_type| pk|old_value|new_value|diff_category|
+-----------+---------+---+---------+---------+-------------+
| price| double| 1| 3.001| 3.0| rounding|
+-----------+---------+---+---------+---------+-------------+
Release files for pyspark-regression 4.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyspark_regression-4.2.4.tar.gz | 20.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyspark_regression-4.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.1 kB
Release files / pyspark_regression-4.2.4.tar.gz
| Download URL | pyspark_regression-4.2.4.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2e6759228584eb35dca66a7cd7e444ec99cc6975b1be3cec5a5c5f258274460
|
|
BLAKE2b-256 checksum How to use checksums |
f947153b6dbfa851e7ecccba49cb642b0a32a357a02ee81963daccde5a5acf06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.
Transparency logRelease files / pyspark_regression-4.2.4-py3-none-any.whl
| Download URL | pyspark_regression-4.2.4-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
850383faac7e2fec98e91933213cbab27050f3687509c065a26bdef88b11cb1a
|
|
BLAKE2b-256 checksum How to use checksums |
b8e7324971a51e6db52783aac6a7fa9678adf9aa8caaf5bfaf8d068b00f815f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 17, 2026.
Transparency log