-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task 33, adding validation id #44
Changes from 5 commits
1d729d8
45c8e84
110720b
da950b6
44612d8
8285ca5
073db36
1d61e97
d70de1b
d91e13a
45ced7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
name="Just a Warning" | ||
) | ||
|
||
error_check_implied = SBLCheck(lambda: Truename="Error Check") | ||
error_check_implied = SBLCheck(lambda: True name="Error Check") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not needed. can you revert this? |
||
|
||
error_check_explicit = SBLCheck( | ||
lambda: True, | ||
|
@@ -32,31 +32,37 @@ | |
|
||
|
||
class SBLCheck(Check): | ||
"""A custom Pandera.Check subclasss that requires a `name` be | ||
"""A custom Pandera.Check subclasss that requires a `name` and an `id` be | ||
specified. Additionally, an attribute named `warning` is added to | ||
the class to enable distinction between warnings and errors. The | ||
default value of warning is `False` which corresponds to an error. | ||
|
||
Don't use this class directly. Make use of the SBLErrorCheck and | ||
SBLWarningCheck subclasses below.""" | ||
|
||
def __init__(self, check_fn: Callable, warning=False, *args, **kwargs): | ||
"""Custom init method that verifies the presence of `name` in | ||
def __init__( | ||
self, check_fn: Callable, id: str = None, warning=False, *args, **kwargs | ||
): | ||
"""Custom init method that verifies the presence of `name` and `id` in | ||
kwargs creates a custom class attribute called `warning`. All | ||
other initializaiton is handled by the parent Check class. | ||
|
||
Args: | ||
check_fn (Callable): A function which evaluates the validity | ||
of the column(s) being tested. | ||
id (str, required): Each check mut have an id. | ||
warning (bool, optional): Boolean specifying whether to | ||
treat the check as a warning rather than an error. | ||
|
||
Raises: | ||
ValueError: Raised if `name` not supplied in kwargs. | ||
ValueError: Raised if `name` not supplied in kwargs and if id is not | ||
supplied or None. | ||
""" | ||
|
||
if "name" not in kwargs: | ||
raise ValueError("Each check must be assigned a `name`.") | ||
self.id = id | ||
|
||
if "name" not in kwargs or id is None: | ||
raise ValueError("Each check must be assigned a `name` and an `id`.") | ||
|
||
# if warning==False treat check as an error check | ||
self.warning = warning | ||
|
@@ -67,10 +73,3 @@ def __init__(self, check_fn: Callable, warning=False, *args, **kwargs): | |
def get_backend(cls, check_obj: Any) -> Type[BaseCheckBackend]: | ||
"""Assume Pandas DataFrame and return PandasCheckBackend""" | ||
return PandasCheckBackend | ||
|
||
|
||
if __name__ == "__main__": | ||
warning_check = SBLCheck(lambda: True, warning=True, name="Just a Warning") | ||
|
||
error_check_implied = SBLCheck(lambda: True, name="Error Check") | ||
error_check_explicit = SBLCheck(lambda: True, warning=False, name="Also an Error") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,19 +25,22 @@ def print_schema_errors(errors: SchemaErrors, phase: str): | |
# Name of the column in the dataframe being checked | ||
schema_error = error["error"] | ||
column_name = schema_error.schema.name | ||
check_id = "n/a" | ||
|
||
# built in checks such as unique=True are different than custom | ||
# checks unfortunately so the name needs to be accessed differently | ||
try: | ||
check_name = schema_error.check.name | ||
check_id = schema_error.check.id | ||
# This will either be a boolean series or a single bool | ||
check_output = schema_error.check_output | ||
except AttributeError: | ||
check_name = schema_error.check | ||
# this is just a string that we'd need to parse manually | ||
check_output = schema_error.args[0] | ||
|
||
print(f"{phase} Validation `{check_name}` failed for column `{column_name}`") | ||
f"{phase} Validation `{check_name}` with id: `{check_id}` \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is missing print. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
failed for column `{column_name}`" | ||
print(check_output) | ||
print("") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into its own file?
following "test_check_functions.py" name, maybe name the new file to be "test_checks.py"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that makes sense. Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these from test_check_functions since they are moved into test_checks file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I did. Let me check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadn't committed the test_chec_functions changes