Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions engarde/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def none_missing(df, columns=None):
raise
return df


def is_monotonic(df, items=None, increasing=None, strict=False):
"""
Asserts that the DataFrame is monotonic.
Expand Down Expand Up @@ -84,6 +85,7 @@ def is_monotonic(df, items=None, increasing=None, strict=False):
raise AssertionError
return df


def is_shape(df, shape):
"""
Asserts that the DataFrame is of a known shape.
Expand Down Expand Up @@ -150,7 +152,7 @@ def unique_index(df):
try:
assert df.index.is_unique
except AssertionError as e:
e.args = df.index.get_duplicates()
e.args = df.index[df.index.duplicated()].unique()
raise
return df

Expand All @@ -176,6 +178,7 @@ def within_set(df, items=None):
raise AssertionError('Not in set', bad)
return df


def within_range(df, items=None):
"""
Assert that a DataFrame is within a range.
Expand All @@ -197,6 +200,7 @@ def within_range(df, items=None):
raise AssertionError("Outside range", bad)
return df


def within_n_std(df, n=3):
"""
Assert that every value is within ``n`` standard
Expand All @@ -220,6 +224,7 @@ def within_n_std(df, n=3):
raise AssertionError(msg)
return df


def has_dtypes(df, items):
"""
Assert that a DataFrame has ``dtypes``
Expand All @@ -237,7 +242,7 @@ def has_dtypes(df, items):
dtypes = df.dtypes
for k, v in items.items():
if not dtypes[k] == v:
raise AssertionError("{} has the wrong dtype. Should be ({}), is ({})".format(k, v,dtypes[k]))
raise AssertionError("{} has the wrong dtype. Should be ({}), is ({})".format(k, v, dtypes[k]))
return df


Expand Down Expand Up @@ -298,4 +303,4 @@ def is_same_as(df, df_to_compare, **kwargs):
__all__ = ['is_monotonic', 'is_same_as', 'is_shape', 'none_missing',
'unique_index', 'within_n_std', 'within_range', 'within_set',
'has_dtypes', 'verify', 'verify_all', 'verify_any',
'one_to_many','is_same_as',]
'one_to_many', 'is_same_as', ]
7 changes: 5 additions & 2 deletions engarde/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def verify(df, check, *args, **kwargs):
raise
return df


def verify_all(df, check, *args, **kwargs):
"""
Verify that all the entries in ``check(df, *args, **kwargs)``
Expand All @@ -51,6 +52,7 @@ def verify_all(df, check, *args, **kwargs):
raise
return df


def verify_any(df, check, *args, **kwargs):
"""
Verify that any of the entries in ``check(df, *args, **kwargs)``
Expand All @@ -69,12 +71,13 @@ def verify_any(df, check, *args, **kwargs):
# Error reporting
# ---------------


def bad_locations(df):
columns = df.columns
all_locs = chain.from_iterable(zip(df.index, cycle([col])) for col in columns)
bad = pd.Series(list(all_locs))[np.asarray(df).ravel(1)]
bad = pd.Series(list(all_locs))[np.asarray(df).ravel(order='F')]
msg = bad.values
return msg

__all__ = ['verify', 'verify_all', 'verify_any', 'bad_locations']

__all__ = ['verify', 'verify_all', 'verify_any', 'bad_locations']