Skip to content

Potential new check: compare_with_value() #69

Description

@emmaKts

Maybe consider the following?

Check a column in a dataframe to make sure all values are greater/lower/equal/ge/le/ than a specific value(not a range).

import operator

def compare_with_value(df, columns, value, which_operator):
    if any(which_operator(column_value, value) for column_value in df[columns].values):       
        raise AssertionError
    return df

Used with a MultiCheck decorator:

@dc.MultiCheck(checks={ck.has_no_nans: {"columns": "test_column"},
                       compare_with_value: {"columns": "test_column",
                                            "which_operator": operator.le,
                                            "value": 10.0
                                            }
                       }
               )

Also, in case it helps anyone:
I tried has_vals_within_range() following this format (i.e. as has_no_nans()):

ck.has_vals_within_range: {"columns": "test_column"}

but it seems that it needs an items element instead (see below).

 ck.has_vals_within_range: {"items": {"test_column": (2, 50)}}

I am just mentioning here as it's minor, but maybe consider renaming "items" to "columns" just for consistency?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requestedwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions