-
Notifications
You must be signed in to change notification settings - Fork 1.2k
change: add modifier for s3_input class #1699
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
Conversation
…thon-sdk into rename-s3-input
…thon-sdk into rename-s3-input
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
"""Classes to modify Predictor code to be compatible | ||
with version 2.0 and later of the SageMaker Python SDK. |
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.
don't forget to update this
|
||
BASE_S3_INPUT = "s3_input" | ||
SESSION = "session" | ||
S3_INPUT = {"s3_input": ("sagemaker", "sagemaker.session")} |
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.
also include sagemaker.inputs
?
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.
Updated the namespaces and added a test case.
from sagemaker.cli.compatibility.v2.modifiers.modifier import Modifier | ||
|
||
BASE_S3_INPUT = "s3_input" | ||
SESSION = "session" |
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 looks to be unused
from sagemaker.cli.compatibility.v2.modifiers import matching | ||
from sagemaker.cli.compatibility.v2.modifiers.modifier import Modifier | ||
|
||
BASE_S3_INPUT = "s3_input" |
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.
maybe S3_INPUT_NAME
instead? I don't think "base" gives much info here.
Returns: | ||
bool: If the import statement imports ``RealTimePredictor`` from the correct module. | ||
""" | ||
return node.module in S3_INPUT[BASE_S3_INPUT] and any( |
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.
seeing this, I think it might be better to define the list of namespaces separately. S3_INPUT[BASE_S3_INPUT]
is a little unintuitive to read on its own here
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.
Yes. I got rid of the dict and used namespaces to check the module.
"""A class to update import statements of ``s3_input``.""" | ||
|
||
def node_should_be_modified(self, node): | ||
"""Checks if the import statement imports ``RealTimePredictor`` from the correct module. |
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.
don't forget to update the docstring
_rename_class(node) | ||
|
||
|
||
def _rename_class(node): |
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 don't know if you need to make this a standalone function, unless maybe if you're refactoring it so that it can be used elsewhere too
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.
Yeah, there's no need to make it a function. I've moved the logic to modify_node
also don't forget to update |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
tests/unit/sagemaker/cli/compatibility/v2/modifiers/test_training_input.py
Show resolved
Hide resolved
tests/unit/sagemaker/cli/compatibility/v2/modifiers/test_training_input.py
Show resolved
Hide resolved
|
||
node = ast_import("from sagemaker.session import s3_input as training_input") | ||
modifier.modify_node(node) | ||
expected_result = "from sagemaker.session import TrainingInput as training_input" |
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.
expected_result = "from sagemaker.session import TrainingInput as training_input" | |
expected_result = "from sagemaker.inputs import TrainingInput as training_input" |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…thon-sdk into rename-s3-input
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
- ``sagemaker.s3_input`` | ||
- ``sagemaker.session.s3_input`` | ||
- ``s3_input`` |
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.
- ``sagemaker.s3_input`` | |
- ``sagemaker.session.s3_input`` | |
- ``s3_input`` | |
- ``sagemaker.s3_input`` | |
- ``sagemaker.inputs.s3_input`` | |
- ``sagemaker.session.s3_input`` | |
- ``s3_input`` |
node = ast_call("s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "TrainingInput(s3_data='s3://a')" == pasta.dump(node) | ||
|
||
node = ast_call("sagemaker.s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "sagemaker.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | ||
|
||
node = ast_call("session.s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | ||
|
||
node = ast_call("inputs.s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | ||
|
||
node = ast_call("sagemaker.inputs.s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | ||
|
||
node = ast_call("sagemaker.session.s3_input(s3_data='s3://a')") | ||
modifier.modify_node(node) | ||
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) |
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.
optional - you could also make an iterable of tuples to reduce how much code is repeated
node = ast_call("s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
node = ast_call("sagemaker.s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "sagemaker.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
node = ast_call("session.s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
node = ast_call("inputs.s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
node = ast_call("sagemaker.inputs.s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
node = ast_call("sagemaker.session.s3_input(s3_data='s3://a')") | |
modifier.modify_node(node) | |
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node) | |
calls = ( | |
("s3_input(s3_data='s3://a')", TrainingInput(s3_data='s3://a')"), | |
("sagemaker.s3_input(s3_data='s3://a')", "sagemaker.TrainingInput(s3_data='s3://a')"), | |
("session.s3_input(s3_data='s3://a')", "inputs.TrainingInput(s3_data='s3://a')"), | |
("inputs.s3_input(s3_data='s3://a')", "inputs.TrainingInput(s3_data='s3://a')"), | |
("sagemaker.inputs.s3_input(s3_data='s3://a')", "sagemaker.inputs.TrainingInput(s3_data='s3://a')"), | |
("sagemaker.session.s3_input(s3_data='s3://a')", "sagemaker.inputs.TrainingInput(s3_data='s3://a')"), | |
) | |
for call, expected in calls: | |
node = ast_call(call) | |
modifier.modify_node(node) | |
assert expected == pasta.dump(node) |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue #, if available:
breaking changes brought in #1680
Description of changes:
Add s3_input modifier to v2 cli.
Convert:
sagemaker.s3_input
-->sagemaker.TrainingInput
s3_input
-->TrainingInput
Testing done:
Unit test
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
unique_name_from_base
to create resource names in integ tests (if appropriate)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.