Skip to content

Commit aa076df

Browse files
committed
deprecation: warn for deprecation - Lambda model-predictor
1 parent aa54685 commit aa076df

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

src/sagemaker/deprecations.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ def renamed_warning(phrase):
5050
_warn(f"{phrase} has been renamed")
5151

5252

53+
def deprecation_warn(name, date, msg=None):
54+
"""Raise a warning for soon to be deprecated feature
55+
in sagemaker>=2
56+
57+
Args:
58+
name (str): Name of the feature
59+
date (str): the date when the feature will be deprecated
60+
msg (str): the prefix phrase of the warning message.
61+
"""
62+
_warn(f"{name} will be deprecated on {date}.{msg}")
63+
64+
65+
def deprecation_warning(date, msg=None):
66+
"""Decorator for raising deprecation warning for a feature
67+
in sagemaker>=2
68+
69+
Args:
70+
date (str): the date when the feature will be deprecated
71+
msg (str): the prefix phrase of the warning message.
72+
73+
Usage:
74+
@deprecation_warning(msg="message", date="date")
75+
def sample_function():
76+
print("xxxx....")
77+
78+
@deprecation_warning(msg="message", date="date")
79+
class SampleClass():
80+
def __init__(self):
81+
print("xxxx....")
82+
83+
"""
84+
def deprecate(obj):
85+
def wrapper(*args, **kwargs):
86+
deprecation_warn(obj.__name__, date, msg)
87+
return obj(*args, **kwargs)
88+
return wrapper
89+
return deprecate
90+
91+
5392
def renamed_kwargs(old_name, new_name, value, kwargs):
5493
"""Checks if the deprecated argument is in kwargs
5594

src/sagemaker/serverless/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
import botocore
2121

2222
from sagemaker.model import ModelBase
23-
23+
from sagemaker.deprecations import deprecation_warning
2424
from .predictor import LambdaPredictor
2525

2626

27+
@deprecation_warning(
28+
msg="Based on customer experience and feedback an"
29+
" alternative support will be added in near future",
30+
date="10/29/2021",
31+
)
2732
class LambdaModel(ModelBase):
2833
"""A model that can be deployed to Lambda."""
2934

src/sagemaker/serverless/predictor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020

2121
from sagemaker import deserializers, serializers
2222
from sagemaker.predictor import PredictorBase
23+
from sagemaker.deprecations import deprecation_warning
2324

2425

26+
@deprecation_warning(
27+
msg="Based on customer experience and feedback an"
28+
" alternative support will be added in near future",
29+
date="10/29/2021",
30+
)
2531
class LambdaPredictor(PredictorBase):
2632
"""A deployed model hosted on Lambda."""
2733

tests/unit/test_deprecations.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
removed_function,
2424
removed_kwargs,
2525
renamed_kwargs,
26+
deprecation_warning,
2627
)
2728

2829

@@ -60,6 +61,50 @@ def test_removed_kwargs():
6061
removed_kwargs("b", kwarg)
6162

6263

64+
def test_deprecation_warning_for_function():
65+
@deprecation_warning(msg="message", date="date")
66+
def sample_function():
67+
return "xxxx...."
68+
69+
with pytest.warns(DeprecationWarning) as w:
70+
output = sample_function()
71+
assert output == "xxxx...."
72+
msg = "sample_function will be deprecated on date.message in sagemaker>=2.\n" \
73+
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
74+
assert str(w[-1].message) == msg
75+
76+
77+
def test_deprecation_warning_for_class():
78+
@deprecation_warning(msg="message", date="date")
79+
class SampleClass():
80+
def __init__(self):
81+
pass
82+
83+
with pytest.warns(DeprecationWarning) as w:
84+
SampleClass()
85+
msg = "SampleClass will be deprecated on date.message in sagemaker>=2.\n" \
86+
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
87+
assert str(w[-1].message) == msg
88+
89+
90+
def test_deprecation_warning_for_class_method():
91+
class SampleClass():
92+
def __init__(self):
93+
pass
94+
95+
@deprecation_warning(msg="message", date="date")
96+
def sample_method(self):
97+
return "xxxx...."
98+
99+
s = SampleClass()
100+
with pytest.warns(DeprecationWarning) as w:
101+
output = s.sample_method()
102+
assert output == "xxxx...."
103+
msg = "sample_method will be deprecated on date.message in sagemaker>=2.\n" \
104+
"See: https://sagemaker.readthedocs.io/en/stable/v2.html for details."
105+
assert str(w[-1].message) == msg
106+
107+
63108
def test_removed_function():
64109
removed = removed_function("foo")
65110
with pytest.warns(DeprecationWarning):

0 commit comments

Comments
 (0)