GeezerVison is showing github.com — fix: Remove unnecessary pandas import from multimodal datasets previe… · googleapis/python-aiplatform@5dd51a2
File treeExpand file treeCollapse file tree Open diff view settings google/cloud/aiplatform/preview
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/preview/datasets.py +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | # | 17 | 17 |
| 18 | 18 | import dataclasses | | 19 | +import io | | 20 | +import json | 19 | 21 | from typing import Dict, List, Optional, Tuple | 20 | 22 | import uuid | 21 | 23 |
| | 32 | 34 | from vertexai import generative_models | 33 | 35 | from vertexai.generative_models import _generative_models | 34 | 36 | from vertexai.preview import prompts | 35 | | -import pandas | 36 | 37 |
| 37 | 38 | from google.protobuf import field_mask_pb2 | 38 | 39 | from google.protobuf import struct_pb2 | @@ -758,7 +759,7 @@ def from_bigquery( | 758 | 759 | def from_pandas( | 759 | 760 | cls, | 760 | 761 | *, | 761 | | - dataframe: pandas.DataFrame, | | 762 | + dataframe: "pandas.DataFrame", # type: ignore # noqa: F821 | 762 | 763 | target_table_id: Optional[str] = None, | 763 | 764 | display_name: Optional[str] = None, | 764 | 765 | project: Optional[str] = None, | @@ -1077,15 +1078,15 @@ def from_gemini_request_jsonl( | 1077 | 1078 |
| 1078 | 1079 | jsonl_string = blob.download_as_text() | 1079 | 1080 | lines = [line.strip() for line in jsonl_string.splitlines() if line.strip()] | 1080 | | - df = pandas.DataFrame(lines, columns=[request_column_name]) | | 1081 | + json_string = json.dumps({request_column_name: lines}) | 1081 | 1082 |
| 1082 | 1083 | session_options = bigframes.BigQueryOptions( | 1083 | 1084 | credentials=credentials, | 1084 | 1085 | project=project, | 1085 | 1086 | location=location, | 1086 | 1087 | ) | 1087 | 1088 | with bigframes.connect(session_options) as session: | 1088 | | - temp_bigframes_df = session.read_pandas(df) | | 1089 | + temp_bigframes_df = session.read_json(io.StringIO(json_string)) | 1089 | 1090 | temp_bigframes_df[request_column_name] = bigframes.bigquery.parse_json( | 1090 | 1091 | temp_bigframes_df[request_column_name] | 1091 | 1092 | ) | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_multimodal_datasets.py +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -584,9 +584,10 @@ def test_create_dataset_from_gemini_request_jsonl( | 584 | 584 | mock_bucket.blob.assert_called_once_with("test-file.jsonl") | 585 | 585 | mock_blob.download_as_text.assert_called_once() | 586 | 586 |
| 587 | | - pandas.testing.assert_frame_equal( | 588 | | - session_mock.read_pandas.call_args[0][0], | 589 | | - pandas.DataFrame({"requests": ["json_line_1", "json_line_2"]}), | | 587 | + session_mock.read_json.assert_called_once() | | 588 | + assert ( | | 589 | + session_mock.read_json.call_args[0][0].getvalue() | | 590 | + == '{"requests": ["json_line_1", "json_line_2"]}' | 590 | 591 | ) | 591 | 592 | bq_client_mock.return_value.copy_table.assert_called_once_with( | 592 | 593 | sources=mock.ANY, | @@ -636,9 +637,10 @@ def test_create_dataset_from_gemini_request_jsonl_without_target_table_id( | 636 | 637 | mock_bucket.blob.assert_called_once_with("test-file.jsonl") | 637 | 638 | mock_blob.download_as_text.assert_called_once() | 638 | 639 |
| 639 | | - pandas.testing.assert_frame_equal( | 640 | | - session_mock.read_pandas.call_args[0][0], | 641 | | - pandas.DataFrame({"requests": ["json_line_1", "json_line_2"]}), | | 640 | + session_mock.read_json.assert_called_once() | | 641 | + assert ( | | 642 | + session_mock.read_json.call_args[0][0].getvalue() | | 643 | + == '{"requests": ["json_line_1", "json_line_2"]}' | 642 | 644 | ) | 643 | 645 |
| 644 | 646 | # Assert that the default BQ dataset is created | |
|