Skip to content

Commit d6e20f6

Browse files
bryanesmithBryan Smith
authored andcommitted
applied blacken formatting
1 parent 2504858 commit d6e20f6

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

google/cloud/aiplatform/featurestore/featurestore.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,11 +1221,10 @@ def batch_serve_to_df(
12211221
if bq_dataset_id is None:
12221222
temp_bq_full_dataset_id = self._get_ephemeral_bq_full_dataset_id(
12231223
featurestore_name_components["featurestore"],
1224-
featurestore_name_components["project"]
1224+
featurestore_name_components["project"],
12251225
)
12261226
temp_bq_dataset = self._create_ephemeral_bq_dataset(
1227-
bigquery_client,
1228-
temp_bq_full_dataset_id
1227+
bigquery_client, temp_bq_full_dataset_id
12291228
)
12301229
temp_bq_batch_serve_table_name = "batch_serve"
12311230
temp_bq_read_instances_table_name = "read_instances"
@@ -1237,8 +1236,8 @@ def batch_serve_to_df(
12371236
temp_bq_batch_serve_table_name = f"tmp_batch_serve_{uuid.uuid4()}".replace(
12381237
"-", "_"
12391238
)
1240-
temp_bq_read_instances_table_name = f"tmp_read_instances_{uuid.uuid4()}".replace(
1241-
"-", "_"
1239+
temp_bq_read_instances_table_name = (
1240+
f"tmp_read_instances_{uuid.uuid4()}".replace("-", "_")
12421241
)
12431242

12441243
temp_bq_batch_serve_table_id = (
@@ -1255,14 +1254,16 @@ def batch_serve_to_df(
12551254
# not Datetime
12561255
job_config = bigquery.LoadJobConfig(
12571256
schema=[
1258-
bigquery.SchemaField("timestamp", bigquery.enums.SqlTypeNames.TIMESTAMP)
1257+
bigquery.SchemaField(
1258+
"timestamp", bigquery.enums.SqlTypeNames.TIMESTAMP
1259+
)
12591260
]
12601261
)
12611262

12621263
job = bigquery_client.load_table_from_dataframe(
12631264
dataframe=read_instances_df,
12641265
destination=temp_bq_read_instances_table_id,
1265-
job_config=job_config
1266+
job_config=job_config,
12661267
)
12671268
job.result()
12681269

@@ -1312,12 +1313,9 @@ def batch_serve_to_df(
13121313

13131314
return pd.concat(frames, ignore_index=True) if frames else pd.DataFrame(frames)
13141315

1315-
13161316
def _get_ephemeral_bq_full_dataset_id(
1317-
self,
1318-
featurestore_id: str,
1319-
project_number: str
1320-
) -> str :
1317+
self, featurestore_id: str, project_number: str
1318+
) -> str:
13211319
temp_bq_dataset_name = f"temp_{featurestore_id}_{uuid.uuid4()}".replace(
13221320
"-", "_"
13231321
)
@@ -1329,11 +1327,8 @@ def _get_ephemeral_bq_full_dataset_id(
13291327

13301328
return f"{project_id}.{temp_bq_dataset_name}"[:1024]
13311329

1332-
13331330
def _create_ephemeral_bq_dataset(
1334-
self,
1335-
bigquery_client: bigquery.Client,
1336-
dataset_id: str
1331+
self, bigquery_client: bigquery.Client, dataset_id: str
13371332
) -> "bigquery.Dataset":
13381333

13391334
temp_bq_dataset = bigquery.Dataset(dataset_ref=dataset_id)

tests/unit/aiplatform/test_featurestores.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ def bq_delete_dataset_mock(bq_client_mock):
417417
with patch.object(bq_client_mock, "delete_dataset") as bq_delete_dataset_mock:
418418
yield bq_delete_dataset_mock
419419

420+
420421
@pytest.fixture
421422
def bq_delete_table_mock(bq_client_mock):
422423
with patch.object(bq_client_mock, "delete_table") as bq_delete_table_mock:
423424
yield bq_delete_table_mock
424425

426+
425427
@pytest.fixture
426428
def bqs_client_mock():
427429
mock = MagicMock(bigquery_storage.BigQueryReadClient)
@@ -1705,7 +1707,13 @@ def test_batch_serve_to_df(self, batch_read_feature_values_mock):
17051707
"get_project_mock",
17061708
)
17071709
@patch("uuid.uuid4", uuid_mock)
1708-
def test_batch_serve_to_df_user_specified_bq_dataset(self, batch_read_feature_values_mock, bq_create_dataset_mock, bq_delete_dataset_mock, bq_delete_table_mock):
1710+
def test_batch_serve_to_df_user_specified_bq_dataset(
1711+
self,
1712+
batch_read_feature_values_mock,
1713+
bq_create_dataset_mock,
1714+
bq_delete_dataset_mock,
1715+
bq_delete_table_mock,
1716+
):
17091717

17101718
aiplatform.init(project=_TEST_PROJECT_DIFF)
17111719

@@ -1715,16 +1723,18 @@ def test_batch_serve_to_df_user_specified_bq_dataset(self, batch_read_feature_va
17151723

17161724
read_instances_df = pd.DataFrame()
17171725

1718-
expected_temp_bq_dataset_name = 'my_dataset_name'
1719-
expected_temp_bq_dataset_id = f"{_TEST_PROJECT}.{expected_temp_bq_dataset_name}"[
1720-
:1024
1721-
]
1722-
expected_temp_bq_batch_serve_table_name = f"tmp_batch_serve_{uuid.uuid4()}".replace(
1723-
"-", "_"
1726+
expected_temp_bq_dataset_name = "my_dataset_name"
1727+
expected_temp_bq_dataset_id = (
1728+
f"{_TEST_PROJECT}.{expected_temp_bq_dataset_name}"[:1024]
17241729
)
1725-
expected_temp_bq_batch_serve_table_id = f"{expected_temp_bq_dataset_id}.{expected_temp_bq_batch_serve_table_name}"
1726-
expected_temp_bq_read_instances_table_name = f"tmp_read_instances_{uuid.uuid4()}".replace(
1727-
"-", "_"
1730+
expected_temp_bq_batch_serve_table_name = (
1731+
f"tmp_batch_serve_{uuid.uuid4()}".replace("-", "_")
1732+
)
1733+
expected_temp_bq_batch_serve_table_id = (
1734+
f"{expected_temp_bq_dataset_id}.{expected_temp_bq_batch_serve_table_name}"
1735+
)
1736+
expected_temp_bq_read_instances_table_name = (
1737+
f"tmp_read_instances_{uuid.uuid4()}".replace("-", "_")
17281738
)
17291739
expected_temp_bq_read_instances_table_id = f"{expected_temp_bq_dataset_id}.{expected_temp_bq_read_instances_table_name}"
17301740

@@ -1751,7 +1761,6 @@ def test_batch_serve_to_df_user_specified_bq_dataset(self, batch_read_feature_va
17511761
bigquery_read_instances=gca_io.BigQuerySource(
17521762
input_uri=f"bq://{expected_temp_bq_read_instances_table_id}"
17531763
),
1754-
17551764
)
17561765
)
17571766

@@ -1779,6 +1788,7 @@ def test_batch_serve_to_df_user_specified_bq_dataset(self, batch_read_feature_va
17791788
bq_create_dataset_mock.assert_not_called()
17801789
bq_delete_dataset_mock.assert_not_called()
17811790

1791+
17821792
class TestEntityType:
17831793
def setup_method(self):
17841794
reload(initializer)

0 commit comments

Comments
 (0)