Skip to main content

pandas-should

pandas-should is pandas extension for asserting.

Install

Install and update released version using pip:

$ pip install pandas-should

If you want development version:

$ pip install git+https://github.com/momijiame/pandas-should.git

Quickstart

You can just to import pandas_should to use:

import pandas_should

DataFrame

Length (rows)

Before:

assert len(df1) == len(df2)

After:

assert df1.should.have_same_length(df2)

Or

assert df1.should.have_length(len(df2))

Before (multiple DataFrame):

assert len(df1) == (len(df2) + len(df3))

After (multiple DataFrame)

assert df1.should.have_same_length(df2, df3)
Width (columns)

Before:

assert len(df1.columns) == len(df2.columns)

After:

assert df1.should.have_same_width(df2)

Or

assert df1.should.have_width(len(df2.columns))

Before (multiple DataFrame):

assert len(df1.columns) == (len(df2.columns)) + len(df3.columns)))

After (multiple DataFrame)

assert df1.should.have_same_width(df2, df3)
Equality

Before:

from pandas.util.testing import assert_frame_equal
def equal(a, b):
    try:
        assert_frame_equal(a, b)
    except AssertionError:
        return False
    return True

assert equal(df1, df2)

After:

assert df1.should.equal(df2)
Null inclusion

Before:

assert df.isnull().any(axis=None)

After:

assert df.should.have_null()

Or expect not to be included:

assert df.should.have_not_null()
assert not df.should.have_null()
Shape

Before:

assert df1.shape == df2.shape

After:

assert df1.should.be_shaped_like(df2)

Or

assert df1.should.be_shaped_like(df2.shape)
assert df1.should.be_shaped_like(df2.shape[0], df2.shape[1])
Value range

Before:

assert (df >= range_min).any(axis=None) and (df <= range_max).any(axis=None) 

After:

assert df.should.fall_within_range(range_min, range_max)

Greater than only:

assert df.should.greater_than(range_min)
assert df.should.greater_than_or_equal(range_min)

Less than only:

assert df.should.less_than(range_min)
assert df.should.less_than_or_equal(range_min)

Series

Length

Before:

assert len(s1) == len(s2)

After:

assert s1.should.have_same_length(s2)

Or:

assert s1.should.have_length(len(s2))

Before (multiple Series):

assert len(s1) == (len(s2) + len(s3))

After (multiple Series):

assert s1.should.have_same_length(s2, s3)
Equality

Before:

from pandas.util.testing import assert_series_equal
def equal(a, b):
    try:
        assert_series_equal(a, b)
    except AssertionError:
        return False
    return True

assert equal(s1, s2)

After:

assert s1.should.equal(s2)
Null inclusion

Before:

assert s.isnull().any()

After:

assert s.should.have_null()

Or expect not to be included:

assert s.should.have_not_null()
assert not s.should.have_null()
Value range

Before:

assert (s >= range_min).any() and (s <= range_max).any() 

After:

assert s.should.fall_within_range(range_min, range_max)

Greater than only:

assert s.should.greater_than(range_min)
assert s.should.greater_than_or_equal(range_min)

Less than only:

assert s.should.less_than(range_min)
assert s.should.less_than_or_equal(range_min)
Value variety

Before:

assert len(s.unique()) == expect_size

After:

assert s.should.have_number_of_unique_values(expect_size)

Metadata

Release files for pandas-should 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pandas-should 0.1.0
File Size Uploaded Provenance Actions
pandas-should-0.1.0.tar.gz 3.9 kB Without provenance Details for pandas-should-0.1.0.tar.gz

Release files / pandas-should-0.1.0.tar.gz

Download URL pandas-should-0.1.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ee7511fd119eaf93396b83c443453f48facfc881846c80336696ebabe0a75690
BLAKE2b-256 checksum
How to use checksums
f3c5f68f953e0b2f0f44b0ac80ff55d27ea0b096a891a5702b610023dbdb6ec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for pandas-should 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page