From b1bcda6501e8d9898c0632193dd6d254c7dd24b7 Mon Sep 17 00:00:00 2001 From: Zax Rosenberg Date: Wed, 9 Jan 2019 15:00:51 -0600 Subject: [PATCH] Hotfix: np.ravel and get_duplicates() future warnings --- engarde/checks.py | 11 ++++++++--- engarde/generic.py | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/engarde/checks.py b/engarde/checks.py index bed8281..18071ea 100644 --- a/engarde/checks.py +++ b/engarde/checks.py @@ -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. @@ -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. @@ -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 @@ -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. @@ -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 @@ -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`` @@ -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 @@ -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', ] diff --git a/engarde/generic.py b/engarde/generic.py index 0265924..b481b10 100644 --- a/engarde/generic.py +++ b/engarde/generic.py @@ -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)`` @@ -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)`` @@ -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']