-
Notifications
You must be signed in to change notification settings - Fork 245
Added feature validation #258
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
Merged
xiaoyongzhu
merged 6 commits into
feathr-ai:main
from
lhayhurst:lhayhurst/feature-name-validation
May 18, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
397ccaa
Added feature name validation
lhayhurst 2a542d9
Merge remote-tracking branch 'linkedin/main' into lhayhurst/feature-n…
lhayhurst 117e6ba
export exceptions by default.
lhayhurst 40ff954
exporting exceptions by default.
lhayhurst 18c1085
PR feedback: one regex for all checks, regex documentation
lhayhurst 7d44555
using import convention
lhayhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
feathr_project/feathr/api/app/core/feathr_api_exception.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,17 @@ | ||
| from app.core.error_code import ErrorCode | ||
|
|
||
| from feathr.api.app.core.error_code import ErrorCode | ||
|
xiaoyongzhu marked this conversation as resolved.
|
||
|
|
||
| class FeathrApiException(Exception): | ||
| def __init__(self,message:str,code:ErrorCode): | ||
| self.code = code | ||
| self.message = message | ||
|
|
||
|
|
||
| class FeatureNameValidationError(ValueError): | ||
| """An exception for feature name validation. | ||
| Feature names must consist of letters, number, or underscores, | ||
| and cannot begin with a number. | ||
| Periods are also disallowed, as some compute engines, such as Spark, | ||
| will consider them as operators in feature name. | ||
| """ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import string | ||
|
|
||
| import pytest | ||
|
|
||
| from feathr import FeatureBase, FeatureNameValidationError | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('bad_feature_name', | ||
| [None, | ||
| '']) | ||
| def test_feature_name_fails_on_empty_name(bad_feature_name: str): | ||
| with pytest.raises(FeatureNameValidationError, match="empty feature name"): | ||
| FeatureBase.validate_feature_name(bad_feature_name) | ||
|
|
||
|
|
||
| def test_feature_name_fails_on_leading_number(): | ||
| with pytest.raises(FeatureNameValidationError, match="cannot start with a number"): | ||
| FeatureBase.validate_feature_name("4featurename") | ||
|
|
||
|
|
||
| def test_feature_name_fails_on_punctuation_chars(): | ||
| for char in set(string.punctuation) - set('_'): | ||
| with pytest.raises(FeatureNameValidationError, match="only letters, numbers, and underscores are allowed"): | ||
| FeatureBase.validate_feature_name(f"feature_{char}_name") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('feature_name', | ||
| ["feature_name", | ||
| "features4lyfe", | ||
| "f_4_feature_", | ||
| "_leading_underscores_are_ok", | ||
| "CapitalizedFeature" | ||
| '']) | ||
| def test_feature_name_validates_ok(feature_name: str): | ||
| assert FeatureBase.validate_feature_name(feature_name) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.