-
Notifications
You must be signed in to change notification settings - Fork 58
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
Update standardizer.py #944
Conversation
Adding a new class called ignore_errors to enable the standardizers to gracefully continue when encountering null key:value pairs
@@ -283,3 +283,19 @@ def __init__( | |||
**kwargs, | |||
): | |||
super().__init__(child, f=standardizer.standardize, args=path, kwargs=kwargs) | |||
|
|||
class IgnoreErrors(standardizer) |
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.
This isn't quite the right syntax, so I don't think this will work.
@bsowell My guess is that we would like to have this logic be more generic, perhaps a subclass of Map
that swallows errors from the function being applied?
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.
It might be worth just making this a function rather than a full class - the main benefit you get from having classes with single static methods is that you can do interfaces and stuff. I don't imagine there will be any other things that follow the same contract as IgnoreErrors
so it should probably just be a function (useable like docset.map(lambda d: ignore_errors(d, standardizer, key_path))
).
If you want to be really fancy (and actually I think this would be a good interface) you can make this a higher-order function - i.e. have it return a function that calls the standardizer and swallows errors. Then the usage can become docset.map(ignore_errors(standardizer, key_path))
.
Update with Henry's feedback
Adding unit tests for ignore_errors
Update helper text
Add types to function
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.
lgtm, just get the linting to work
Shorten line in imports
Reduce line length from helper text
Adding a new class called ignore_errors to enable the standardizers to gracefully continue when encountering null key:value pairs