From 8e42bc5e97d7f74a7ccba059be8327c61a342391 Mon Sep 17 00:00:00 2001 From: Jaycee Li Date: Tue, 24 Oct 2023 15:04:46 -0700 Subject: [PATCH] chore: fix attribute errors on external packages when importing SDK PiperOrigin-RevId: 576296610 --- google/cloud/aiplatform/jobs.py | 10 ++++++---- .../_workflow/serialization_engine/serializers_base.py | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/google/cloud/aiplatform/jobs.py b/google/cloud/aiplatform/jobs.py index 3ac363a761..bb9f82c4eb 100644 --- a/google/cloud/aiplatform/jobs.py +++ b/google/cloud/aiplatform/jobs.py @@ -24,9 +24,6 @@ import tempfile import uuid -from google.cloud import storage -from google.cloud import bigquery - from google.auth import credentials as auth_credentials from google.protobuf import duration_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -892,7 +889,9 @@ def _create( def iter_outputs( self, bq_max_results: Optional[int] = 100 - ) -> Union[Iterable[storage.Blob], Iterable[bigquery.table.RowIterator]]: + ) -> Union[ + Iterable["storage.Blob"], Iterable["bigquery.table.RowIterator"] # noqa: F821 + ]: """Returns an Iterable object to traverse the output files, either a list of GCS Blobs or a BigQuery RowIterator depending on the output config set when the BatchPredictionJob was created. @@ -916,6 +915,9 @@ def iter_outputs( If BatchPredictionJob succeeded and output_info does not have a GCS or BQ output provided. """ + # pylint: disable=g-import-not-at-top + from google.cloud import bigquery + from google.cloud import storage self._assert_gca_resource_is_available() diff --git a/vertexai/preview/_workflow/serialization_engine/serializers_base.py b/vertexai/preview/_workflow/serialization_engine/serializers_base.py index 4b14173b85..86ea8656d9 100644 --- a/vertexai/preview/_workflow/serialization_engine/serializers_base.py +++ b/vertexai/preview/_workflow/serialization_engine/serializers_base.py @@ -58,7 +58,9 @@ import sklearn SklearnEstimator = sklearn.base.BaseEstimator -except ImportError: +# Temp fix for sklearn version too old and doesn't have `base` attribute +# TODO(b/307540407) Lazy import on external pckages +except (ImportError, AttributeError): sklearn = None SklearnEstimator = Any