Skip to main content

Inspired by the library great-expectations

Project description

Great Assertions

serialbandicoot flake8 Lint codecov CodeQL

This library is inspired by the Great Expectations library. The library has made the various expectations found in Great Expectations available when using the inbuilt python unittest assertions.

For example if you wanted to use expect_column_values_to_be_between then you can access assertExpectColumnValuesToBeBetween.

Install

pip install great-assertions

Code example Pandas

from great_assertions import GreatAssertions
import pandas as pd

class GreatAssertionTests(GreatAssertions):
    def test_expect_table_row_count_to_equal(self):
        df = pd.DataFrame({"col_1": [100, 200, 300], "col_2": [10, 20, 30]})
        self.assertExpectTableRowCountToEqual(df, 3)

Code example PySpark

from great_assertions import GreatAssertions
from pyspark.sql import SparkSession

class GreatAssertionTests(GreatAssertions):

    def setUp(self):
        self.spark = SparkSession.builder.getOrCreate()

    def test_expect_table_row_count_to_equal(self):
        df = self.spark.createDataFrame(
            [
                {"col_1": 100, "col_2": 10},
                {"col_1": 200, "col_2": 20},
                {"col_1": 300, "col_2": 30},
            ]
        )
        self.assertExpectTableRowCountToEqual(df, 3)

List of available assertions

Pandas PySpark
assertExpectTableRowCountToEqual :white_check_mark: :white_check_mark:
assertExpectColumnValuesToBeBetween :white_check_mark: :white_check_mark:
assertExpectColumnValuesToMatchRegex :white_check_mark: :white_check_mark:
assertExpectColumnValuesToBeInSet :white_check_mark: :white_check_mark:
assertExpectColumnValuesToBeOfType :white_check_mark: :white_check_mark:
assertExpectTableColumnsToMatchOrderedList :white_check_mark: :white_check_mark:
assertExpectTableColumnsToMatchSet :white_check_mark: :white_check_mark:
assertExpectDateRangeToBeMoreThan :white_check_mark: :white_check_mark:
assertExpectDateRangeToBeLessThan :white_check_mark: :white_check_mark:
assertExpectDateRangeToBeBetween :white_check_mark: :white_check_mark:
assertExpectColumnMeanToBeBetween :white_check_mark: :white_check_mark:
assertExpectColumnValueCountsPercentToBeBetween :white_check_mark: :white_check_mark:

Assertion Descriptions

For a description of the assertions see Assertion Definitions

Running the tests

Executing the tests still require unittest, the following options have been tested with the examples provided.

Option 1

import unittest
suite = unittest.TestLoader().loadTestsFromTestCase(GreatAssertionTests)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite) 

Options 2

if __name__ == '__main__':
    unittest.main()   

Notes

If you get an arrows function warning when running in Databricks, this will happen becuase a toPandas() method is called. The plan is to remove pandas conversion for Spark at a later date as use native PySpark code. For make sure the datasets are not too big, to cause the driver to crash.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

great-assertions-0.0.29.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

great_assertions-0.0.29-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file great-assertions-0.0.29.tar.gz.

File metadata

  • Download URL: great-assertions-0.0.29.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for great-assertions-0.0.29.tar.gz
Algorithm Hash digest
SHA256 ef520b1ef8060df62bd74e1b4635f0bd02098b229a14cf15a6ac6f8ab0d21a4c
MD5 6ef9b452af17f806ffa5365b85780ee6
BLAKE2b-256 22d2a79284c0cb69aee486a227baf80cce8ffcf09103bd538447a7e2bef97fde

See more details on using hashes here.

File details

Details for the file great_assertions-0.0.29-py3-none-any.whl.

File metadata

  • Download URL: great_assertions-0.0.29-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for great_assertions-0.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 9e80aff0b504d29216d7de061695e84c50afecb1e3e7c36e210112535b21dc7d
MD5 a360dc13249eac2030dfa7451f20d237
BLAKE2b-256 bd6957cca26d640d9e76a1457c2d3c23f9dcd4801a6f5d943f7f75cddbd10f86

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page