Skip to main content

Test driven data-wrangling and data validation.

Project description

Apache 2.0 License Supported Python Versions Installation Requirements Development Repository Current Build Status Development Status Documentation (stable) Documentation (latest)

Datatest helps to speed up and formalize data-wrangling and data validation tasks. It implements a system of validation methods, difference classes, and acceptance managers. Datatest can help you:

  • Clean and wrangle data faster and more accurately.

  • Maintain a record of checks and decisions regarding important data sets.

  • Distinguish between ideal criteria and acceptible deviation.

  • Validate the input and output of data pipeline components.

  • Measure progress of data preparation tasks.

  • On-board new team members with an explicit and structured process.

Datatest can be used directly in your own projects or as part of a testing framework like pytest or unittest. It has no hard dependencies; it’s tested on Python 2.6, 2.7, 3.2 through 3.10, PyPy, and PyPy3; and is freely available under the Apache License, version 2.

Documentation:
Official:

Code Examples

Validating a Dictionary of Lists

from datatest import validate, accepted, Invalid


data = {
    'A': [1, 2, 3, 4],
    'B': ['x', 'y', 'x', 'x'],
    'C': ['foo', 'bar', 'baz', 'EMPTY']
}

validate(data.keys(), {'A', 'B', 'C'})

validate(data['A'], int)

validate(data['B'], {'x', 'y'})

with accepted(Invalid('EMPTY')):
    validate(data['C'], str.islower)

Validating a Pandas DataFrame

import pandas as pd
from datatest import register_accessors, accepted, Invalid


register_accessors()
df = pd.read_csv('data.csv')

df.columns.validate({'A', 'B', 'C'})

df['A'].validate(int)

df['B'].validate({'x', 'y'})

with accepted(Invalid('EMPTY')):
    df['C'].validate(str.islower)

Installation

The easiest way to install datatest is to use pip:

pip install datatest

If you are upgrading from version 0.11.0 or newer, use the --upgrade option:

pip install --upgrade datatest

Upgrading From Version 0.9.6

If you have an existing codebase of older datatest scripts, you should upgrade using the following steps:

  • Install datatest 0.10.0 first:

    pip install --force-reinstall datatest==0.10.0
  • Run your existing code and check for DeprecationWarnings.

  • Update the parts of your code that use deprecated features.

  • Once your code is running without DeprecationWarnings, install the latest version of datatest:

    pip install --upgrade datatest

Stuntman Mike

If you need bug-fixes or features that are not available in the current stable release, you can “pip install” the development version directly from GitHub:

pip install --upgrade https://github.com/shawnbrown/datatest/archive/master.zip

All of the usual caveats for a development install should apply—only use this version if you can risk some instability or if you know exactly what you’re doing. While care is taken to never break the build, it can happen.

Safety-first Clyde

If you need to review and test packages before installing, you can install datatest manually.

Download the latest source distribution from the Python Package Index (PyPI):

https://pypi.org/project/datatest/#files

Unpack the file (replacing X.Y.Z with the appropriate version number) and review the source code:

tar xvfz datatest-X.Y.Z.tar.gz

Change to the unpacked directory and run the tests:

cd datatest-X.Y.Z
python setup.py test

Don’t worry if some of the tests are skipped. Tests for optional data sources (like pandas DataFrames or NumPy arrays) are skipped when the related third-party packages are not installed.

If the source code and test results are satisfactory, install the package:

python setup.py install

Supported Versions

Tested on Python 2.6, 2.7, 3.2 through 3.10, PyPy, and PyPy3. Datatest is pure Python and may also run on other implementations as well (check using “setup.py test” before installing).

Backward Compatibility

If you have existing tests that use API features which have changed since 0.9.0, you can still run your old code by adding the following import to the beginning of each file:

from datatest.__past__ import api09

To maintain existing test code, this project makes a best-effort attempt to provide backward compatibility support for older features. The API will be improved in the future but only in measured and sustainable ways.

All of the data used at the National Committee for an Effective Congress has been checked with datatest for several years so there is, already, a large and growing codebase that relies on current features and must be maintained into the future.

Soft Dependencies

Datatest has no hard, third-party dependencies. But if you want to interface with pandas DataFrames, NumPy arrays, or other optional data sources, you will need to install the relevant packages (pandas, numpy, etc.).

Development Repository

The development repository for datatest is hosted on GitHub.


Freely licensed under the Apache License, Version 2.0

Copyright 2014 - 2021 National Committee for an Effective Congress, et al.

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

datatest-0.11.1.tar.gz (109.0 kB view details)

Uploaded Source

Built Distribution

datatest-0.11.1-py2.py3-none-any.whl (141.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file datatest-0.11.1.tar.gz.

File metadata

  • Download URL: datatest-0.11.1.tar.gz
  • Upload date:
  • Size: 109.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2

File hashes

Hashes for datatest-0.11.1.tar.gz
Algorithm Hash digest
SHA256 883b8780a3525f551837505cb64b2a23c16057c3189711fa47206e053840f8c5
MD5 cc05cc26e8f79e3b81a1e749c4e5c090
BLAKE2b-256 3759b42ea7bebd2af436338a383f665ab22e4772dbf756b99556b50b5f91aa29

See more details on using hashes here.

File details

Details for the file datatest-0.11.1-py2.py3-none-any.whl.

File metadata

  • Download URL: datatest-0.11.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 141.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.2

File hashes

Hashes for datatest-0.11.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d62959173c660170e12c9dc008b54884b8ab78cd7cb677d21da76979cee99648
MD5 e4d949c71f49e197467cb106fa4e04b3
BLAKE2b-256 07b6c90e8b6173834e18409e4d739234226c50c9e6bdfb0b161ed21a0d05f78b

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