Skip to content

Commit 8ae9f68

Browse files
authored
breaking: Remove the content_types module (#1744)
1 parent d4f7ce8 commit 8ae9f68

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

doc/v2.rst

+22
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ Please use :func:`sagemaker.predictor.Predictor.delete_endpoint` instead.
7070
The ``update_endpoint`` argument in ``deploy()`` methods for estimators and models has been deprecated.
7171
Please use :func:`sagemaker.predictor.Predictor.update_endpoint` instead.
7272

73+
``sagemaker.content_types``
74+
---------------------------
75+
76+
The ``sagemaker.content_types`` module is removed in v2.0 and later of the
77+
SageMaker Python SDK.
78+
79+
Instead of importing constants from ``sagemaker.content_types``, explicitly
80+
write MIME types as a string,
81+
82+
+-------------------------------+--------------------------------+
83+
| v1.x | v2.0 and later |
84+
+===============================+================================+
85+
| ``CONTENT_TYPE_JSON`` | ``"application/json"`` |
86+
+-------------------------------+--------------------------------+
87+
| ``CONTENT_TYPE_CSV`` | ``"text/csv"`` |
88+
+-------------------------------+--------------------------------+
89+
| ``CONTENT_TYPE_OCTET_STREAM`` | ``"application/octet-stream"`` |
90+
+-------------------------------+--------------------------------+
91+
| ``CONTENT_TYPE_NPY`` | ``"application/x-npy"`` |
92+
+-------------------------------+--------------------------------+
93+
94+
7395
Require ``framework_version`` and ``py_version`` for Frameworks
7496
===============================================================
7597

src/sagemaker/content_types.py

-19
This file was deleted.

src/sagemaker/sparkml/model.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from __future__ import absolute_import
1515

1616
from sagemaker import Model, Predictor, Session, image_uris
17-
from sagemaker.content_types import CONTENT_TYPE_CSV
1817
from sagemaker.serializers import CSVSerializer
1918

2019
framework_name = "sparkml-serving"
@@ -50,7 +49,7 @@ def __init__(self, endpoint_name, sagemaker_session=None):
5049
endpoint_name=endpoint_name,
5150
sagemaker_session=sagemaker_session,
5251
serializer=CSVSerializer(),
53-
content_type=CONTENT_TYPE_CSV,
52+
content_type="text/csv",
5453
)
5554

5655

src/sagemaker/tensorflow/model.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import sagemaker
1919
from sagemaker import image_uris
20-
from sagemaker.content_types import CONTENT_TYPE_JSON
2120
from sagemaker.deserializers import JSONDeserializer
2221
from sagemaker.predictor import Predictor
2322
from sagemaker.serializers import JSONSerializer
@@ -96,7 +95,7 @@ def _classify_or_regress(self, data, method):
9695
if method not in ["classify", "regress"]:
9796
raise ValueError("invalid TensorFlow Serving method: {}".format(method))
9897

99-
if self.content_type != CONTENT_TYPE_JSON:
98+
if self.content_type != "application/json":
10099
raise ValueError("The {} api requires json requests.".format(method))
101100

102101
args = {"CustomAttributes": "tfs-method={}".format(method)}

tests/integ/test_inference_pipeline.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
)
2424

2525
from sagemaker import image_uris
26-
from sagemaker.content_types import CONTENT_TYPE_CSV
2726
from sagemaker.model import Model
2827
from sagemaker.pipeline import PipelineModel
2928
from sagemaker.predictor import Predictor
@@ -87,9 +86,7 @@ def test_inference_pipeline_batch_transform(sagemaker_session, cpu_instance_type
8786
with timeout_and_delete_model_with_transformer(
8887
transformer, sagemaker_session, minutes=TRANSFORM_DEFAULT_TIMEOUT_MINUTES
8988
):
90-
transformer.transform(
91-
transform_input, content_type=CONTENT_TYPE_CSV, job_name=batch_job_name
92-
)
89+
transformer.transform(transform_input, content_type="text/csv", job_name=batch_job_name)
9390
transformer.wait()
9491

9592

@@ -134,8 +131,8 @@ def test_inference_pipeline_model_deploy(sagemaker_session, cpu_instance_type):
134131
endpoint_name=endpoint_name,
135132
sagemaker_session=sagemaker_session,
136133
serializer=JSONSerializer,
137-
content_type=CONTENT_TYPE_CSV,
138-
accept=CONTENT_TYPE_CSV,
134+
content_type="text/csv",
135+
accept="text/csv",
139136
)
140137

141138
with open(VALID_DATA_PATH, "r") as f:

tests/integ/test_multi_variant_endpoint.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from sagemaker.s3 import S3Uploader
2424
from sagemaker.session import production_variant
2525
from sagemaker.sparkml import SparkMLModel
26-
from sagemaker.content_types import CONTENT_TYPE_CSV
2726
from sagemaker.utils import unique_name_from_base
2827
from sagemaker.predictor import Predictor
2928
from sagemaker.serializers import CSVSerializer
@@ -153,17 +152,17 @@ def test_target_variant_invocation(sagemaker_session, multi_variant_endpoint):
153152
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
154153
EndpointName=multi_variant_endpoint.endpoint_name,
155154
Body=TEST_CSV_DATA,
156-
ContentType=CONTENT_TYPE_CSV,
157-
Accept=CONTENT_TYPE_CSV,
155+
ContentType="text/csv",
156+
Accept="text/csv",
158157
TargetVariant=TEST_VARIANT_1,
159158
)
160159
assert response["InvokedProductionVariant"] == TEST_VARIANT_1
161160

162161
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
163162
EndpointName=multi_variant_endpoint.endpoint_name,
164163
Body=TEST_CSV_DATA,
165-
ContentType=CONTENT_TYPE_CSV,
166-
Accept=CONTENT_TYPE_CSV,
164+
ContentType="text/csv",
165+
Accept="text/csv",
167166
TargetVariant=TEST_VARIANT_2,
168167
)
169168
assert response["InvokedProductionVariant"] == TEST_VARIANT_2
@@ -174,8 +173,8 @@ def test_predict_invocation_with_target_variant(sagemaker_session, multi_variant
174173
endpoint_name=multi_variant_endpoint.endpoint_name,
175174
sagemaker_session=sagemaker_session,
176175
serializer=CSVSerializer(),
177-
content_type=CONTENT_TYPE_CSV,
178-
accept=CONTENT_TYPE_CSV,
176+
content_type="text/csv",
177+
accept="text/csv",
179178
)
180179

181180
# Validate that no exception is raised when the target_variant is specified.
@@ -191,8 +190,8 @@ def test_variant_traffic_distribution(sagemaker_session, multi_variant_endpoint)
191190
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
192191
EndpointName=multi_variant_endpoint.endpoint_name,
193192
Body=TEST_CSV_DATA,
194-
ContentType=CONTENT_TYPE_CSV,
195-
Accept=CONTENT_TYPE_CSV,
193+
ContentType="text/csv",
194+
Accept="text/csv",
196195
)
197196
if response["InvokedProductionVariant"] == TEST_VARIANT_1:
198197
variant_1_invocation_count += 1
@@ -274,17 +273,17 @@ def test_target_variant_invocation_local_mode(sagemaker_session, multi_variant_e
274273
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
275274
EndpointName=multi_variant_endpoint.endpoint_name,
276275
Body=TEST_CSV_DATA,
277-
ContentType=CONTENT_TYPE_CSV,
278-
Accept=CONTENT_TYPE_CSV,
276+
ContentType="text/csv",
277+
Accept="text/csv",
279278
TargetVariant=TEST_VARIANT_1,
280279
)
281280
assert response["InvokedProductionVariant"] == TEST_VARIANT_1
282281

283282
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(
284283
EndpointName=multi_variant_endpoint.endpoint_name,
285284
Body=TEST_CSV_DATA,
286-
ContentType=CONTENT_TYPE_CSV,
287-
Accept=CONTENT_TYPE_CSV,
285+
ContentType="text/csv",
286+
Accept="text/csv",
288287
TargetVariant=TEST_VARIANT_2,
289288
)
290289
assert response["InvokedProductionVariant"] == TEST_VARIANT_2
@@ -302,8 +301,8 @@ def test_predict_invocation_with_target_variant_local_mode(
302301
endpoint_name=multi_variant_endpoint.endpoint_name,
303302
sagemaker_session=sagemaker_session,
304303
serializer=CSVSerializer(),
305-
content_type=CONTENT_TYPE_CSV,
306-
accept=CONTENT_TYPE_CSV,
304+
content_type="text/csv",
305+
accept="text/csv",
307306
)
308307

309308
# Validate that no exception is raised when the target_variant is specified.

tests/integ/test_tuner_multi_algo.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from sagemaker import image_uris, utils
2121
from sagemaker.analytics import HyperparameterTuningJobAnalytics
22-
from sagemaker.content_types import CONTENT_TYPE_JSON
2322
from sagemaker.deserializers import JSONDeserializer
2423
from sagemaker.estimator import Estimator
2524
from sagemaker.tuner import ContinuousParameter, IntegerParameter, HyperparameterTuner
@@ -215,7 +214,7 @@ def _create_training_inputs(sagemaker_session):
215214

216215
def _make_prediction(predictor, data):
217216
predictor.serializer = _prediction_data_serializer
218-
predictor.content_type = CONTENT_TYPE_JSON
217+
predictor.content_type = "application/json"
219218
predictor.deserializer = JSONDeserializer()
220219
return predictor.predict(data)
221220

0 commit comments

Comments
 (0)