Skip to main content

Test driven data wrangling.

Project description

https://api.travis-ci.org/shawnbrown/datatest.png

Datatest extends the Python standard library’s unittest package to provide testing tools for asserting data correctness.

Data errors can be identified quickly with a list of differences showing where data fails to satisfy a given requirement:

Traceback (most recent call last):
  File "test_census_update.py", line 13, in test_columns
    self.assertSubjectSum('population', ['county'])
datatest.error.DataError: different column sums:
 Deviation(-1, 71372, county='Franklin'),
 Deviation(+8, 160248, county='Jackson'),
 Deviation(+1, 116229, county='Jefferson'),
 Deviation(-3, 17581, county='Washington')

When some differences are acceptable, they can be allowed using a context manager:

with self.allowDeviation(8):  # Allows +/- 8.
    self.assertSubjectSum('population', ['county'])

Datatest can help prepare messy data that needs to be cleaned, integrated, formatted, and verified. It can provide structure for the tidying process, automate checklists, log discrepancies, and measure progress.

Installation

The easiest way to install datatest is to use pip:

pip install datatest

Stuntman Mike

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

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

All of the usual caveats of a bleeding-edge install should apply here. Only use an unstable development 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.python.org/pypi/datatest

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 MS Excel files) 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 versions 3.5, 3.4, 3.3, 3.2, 3.1, 2.7 and 2.6. Datatest is pure Python and is likely to run on PyPy, Jython, and other implementations without issues (check with “setup.py test” before installing).

Future Plans

I’m aiming to release a 1.0.0, stable API by the end of the year. But before this happens, I want to get some feedback, add support for more data sources, and improve py.test integration (including a py.test plugin).

As I tighten the integration with unittest and py.test, expect some assertions and properties to be renamed. But don’t panic—test suites that rely on the current version’s assertion names (version 0.6.0.dev1) will still run by adding the following import to the beginning of each file:

from datatest.__past__ import api_dev1

This said, all of the data used at the National Committee for an Effective Congress has been checked with datatest for more than a year so there is, already, an existing codebase that relies on current features and must be maintained into the future. It is my intention that the API only change in measured and sustainable ways.

Dependencies

There are no hard dependencies. But if you want to interface with pandas DataFrames, MS Excel workbooks, or other optional data sources, you will need to install the relevant third-party packages (pandas, xlrd, etc.).


Freely licensed under the Apache License, Version 2.0

Copyright 2014 - 2016 NCEC Services, LLC and contributing authors

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.6.0.dev1.tar.gz (73.2 kB view details)

Uploaded Source

Built Distribution

datatest-0.6.0.dev1-py2.py3-none-any.whl (47.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file datatest-0.6.0.dev1.tar.gz.

File metadata

  • Download URL: datatest-0.6.0.dev1.tar.gz
  • Upload date:
  • Size: 73.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for datatest-0.6.0.dev1.tar.gz
Algorithm Hash digest
SHA256 87ef8769014fe904ed2d21de607d3f86a9a77457a25194c683b06a49e7cb2020
MD5 fdaf5291e877d2f9e6193951f2a949de
BLAKE2b-256 1b380bed8fc4ce160d02b235aca3c665166de9be840c95dd3ac4519ca76e8db5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datatest-0.6.0.dev1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a7e3396c3bd4cc8fe7378ebc7dd78a97950c61a0f858a82c0aa3740d95d83dfe
MD5 4f6ec61e9d7e9d61d3a342e7671597ad
BLAKE2b-256 dd49044a4f4f04c19da456615b1bb30fa4b4261095703138ffc2cf2e651aa4c1

See more details on using hashes here.

Supported by

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