def test_deferred_error(): de = DeferredError(ImportError("pretend the import failed")) with pytest.raises(ImportError) as _: # noqa: F841 de.something()
import tempfile import time import sagemaker.local.data from sagemaker.local.image import _SageMakerContainer from sagemaker.local.utils import copy_directory_structure, move_to_destination, get_docker_host from sagemaker.utils import DeferredError, get_config_value logger = logging.getLogger(__name__) try: import urllib3 except ImportError as e: logger.warning("urllib3 failed to import. Local mode features will be impaired or broken.") # Any subsequent attempt to use urllib3 will raise the ImportError urllib3 = DeferredError(e) _UNUSED_ARN = "local:arn-does-not-matter" HEALTH_CHECK_TIMEOUT_LIMIT = 120 class _LocalProcessingJob: """Defines and starts a local processing job.""" _STARTING = "Starting" _PROCESSING = "Processing" _COMPLETED = "Completed" def __init__(self, container): """Creates a local processing job.
import csv import abc import codecs import io import json import numpy as np from sagemaker.utils import DeferredError try: import pandas except ImportError as e: pandas = DeferredError(e) class BaseDeserializer(abc.ABC): """Abstract base class for creation of new deserializers. Provides a skeleton for customization requiring the overriding of the method deserialize and the class attribute ACCEPT. """ @abc.abstractmethod def deserialize(self, stream, content_type): """Deserialize data received from an inference endpoint. Args: stream (botocore.response.StreamingBody): Data to be deserialized. content_type (str): The MIME type of the data.
import datetime import logging from six import with_metaclass from sagemaker.session import Session from sagemaker.utils import DeferredError, extract_name_from_job_arn try: import pandas as pd except ImportError as e: logging.warning( "pandas failed to import. Analytics features will be impaired or broken." ) # Any subsequent attempt to use pandas will raise the ImportError pd = DeferredError(e) class AnalyticsMetricsBase(with_metaclass(ABCMeta, object)): """Base class for tuning job or training job analytics classes. Understands common functionality like persistence and caching. """ def export_csv(self, filename): """Persists the analytics dataframe to a file. Args: filename (str): The name of the file to save to. """ self.dataframe().to_csv(filename) def dataframe(self, force_refresh=False):
from __future__ import absolute_import import abc from collections.abc import Iterable import csv import io import json import numpy as np from sagemaker.utils import DeferredError try: import scipy.sparse except ImportError as e: scipy = DeferredError(e) class BaseSerializer(abc.ABC): """Abstract base class for creation of new serializers. Provides a skeleton for customization requiring the overriding of the method serialize and the class attribute CONTENT_TYPE. """ @abc.abstractmethod def serialize(self, data): """Serialize data into the media type specified by CONTENT_TYPE. Args: data (object): Data to be serialized.
def test_deferred_error(): de = DeferredError(ImportError("pretend the import failed")) with pytest.raises(ImportError) as _: # noqa: F841 de.something()