-
Notifications
You must be signed in to change notification settings - Fork 322
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
Add validate
to SingleTableMetadata
#930
Conversation
|
||
@staticmethod | ||
def _validate_datetime(column_name, **kwargs): | ||
datetime_format = kwargs.get('datetime_format') | ||
if datetime_format: | ||
if datetime_format is not None: |
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.
Unrelated. It was not validating if the value was an empty string.
The #879 issue asks us to test |
14d8108
to
5e4f658
Compare
Codecov Report
@@ Coverage Diff @@
## V1.0.0.dev #930 +/- ##
==============================================
+ Coverage 72.73% 73.17% +0.43%
==============================================
Files 40 40
Lines 3323 3377 +54
==============================================
+ Hits 2417 2471 +54
Misses 906 906
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
c7c61c9
to
06b9dbe
Compare
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.
Left a few comments to help understand the code. Messages marked with Unrelated
mean they are standalone and unrelated to the PR itself.
@@ -135,16 +136,16 @@ def _validate_metadata_columns(cls, metadata, **kwargs): | |||
else: | |||
column_names = kwargs.get('column_names') | |||
|
|||
missing_columns = set(column_names) - set(metadata._columns) | |||
|
|||
missing_columns = set(column_names) - set(metadata._columns) - {None} |
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.
Unrelated. This happens when a column name was not passed/is missing.
raise ConstraintMetadataError( | ||
f'A {cls.__name__} constraint is being applied to invalid column names ' | ||
f'{article} {cls.__name__} constraint is being applied to invalid column names ' |
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.
Unrelated.
@@ -250,55 +248,90 @@ def _validate_datatype(id): | |||
"""Check whether id is a string or a tuple of strings.""" | |||
return isinstance(id, str) or isinstance(id, tuple) and all(isinstance(i, str) for i in id) | |||
|
|||
def _validate_key(self, id, key_type): |
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.
The previous implementation had the validation inside the set_key methods. Pulling it out of the key methods so I can use it in the validate
method.
|
||
self._metadata['sequence_index'] = column_name | ||
def _validate_constraint(self, constraint_name, **kwargs): |
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.
Pulling this out of add_constraint
because I need it in for validate
.
try: | ||
self._validate_constraint(constraint_name, **kwargs) | ||
except MultipleConstraintsErrors as e: | ||
reformated_errors = '\n'.join(map(str, e.errors)) |
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.
Need to do this because MultipleConstraintsErrors
sets it's own __str__
, which messes up the formatting of the error message.
|
||
def to_dict(self): | ||
"""Return a python ``dict`` representation of the ``SingleTableMetadata``.""" | ||
metadata = {} | ||
for key, value in self._metadata.items(): | ||
for key in self._KEYS: |
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.
Change needed because we deleted _metadata.
@@ -990,7 +990,7 @@ def test__validate_metadata_specific_to_constraint_datetime_error(self): | |||
|
|||
# Run | |||
error_message = re.escape( | |||
'An Inequality constraint is being applied to mismatched sdtypes ' | |||
'An Inequality constraint is being applied to mismatched sdtype columns ' |
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.
Unrelated. Phrasing was confusing, it made it seem the values were sdtypes when they are actually columns.
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.
minor: can we reword to is being applied to columns with mismatched sdtypes
then? I think that makes more sense
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.
Looking good. A few minor comments
@@ -990,7 +990,7 @@ def test__validate_metadata_specific_to_constraint_datetime_error(self): | |||
|
|||
# Run | |||
error_message = re.escape( | |||
'An Inequality constraint is being applied to mismatched sdtypes ' | |||
'An Inequality constraint is being applied to mismatched sdtype columns ' |
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.
minor: can we reword to is being applied to columns with mismatched sdtypes
then? I think that makes more sense
@amontanez24 I'm not sure what you mean here: #930 (comment), it was already changed in the base. |
you're right, I read something wrong |
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.
Some very minor comments, but I think this is good to go!
self._append_error(errors, self._validate_column, column, **kwargs) | ||
|
||
if errors: | ||
raise InvalidMetadataError( |
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.
Not necessary for this PR but later I think we might want to make a custom error that takes a list of errors and joins them in the message. We're probably going to be doing that a lot in the future
… be list of tuple
ee9284f
to
af34779
Compare
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
* Add key validation methods (the methods themselves still gotta be revised) * Combined errors implementation * Finish constraints * Add silly constraint solution * Add try/catches for validation + add unit and integration tests * Change MetadataError to InvalidMetadataError * Simplify tests to one element + fix lint * Remove _metadata * Change way _metadata implemented in to_dict * Add constraint validation + integration test + change _constraints to be list of tuple * Fix error message for validate + add error integration test * Fix all constraint related error messages * Add helper _append_error to validate + fix constraint related errors * Add constraint unit test * Fix lint * change _metadata[pk] to pk * Add tests requested + addresses feedback * Address minor feedback
Resolve #879.