Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit ad0f33c

Browse filesBrowse files
authored
docs: fix cast method shown on public docs (#2436)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 51309df commit ad0f33c
Copy full SHA for ad0f33c

7 files changed

+37-29Lines changed: 37 additions & 29 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bigframes/ml/base.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/base.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"""
2525

2626
import abc
27-
from typing import cast, Optional, TypeVar, Union
27+
import typing
28+
from typing import Optional, TypeVar, Union
2829
import warnings
2930

3031
import bigframes_vendored.sklearn.base
@@ -133,7 +134,7 @@ def register(self: _T, vertex_ai_model_id: Optional[str] = None) -> _T:
133134
self._bqml_model = self._create_bqml_model() # type: ignore
134135
except AttributeError:
135136
raise RuntimeError("A model must be trained before register.")
136-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
137+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
137138

138139
self._bqml_model.register(vertex_ai_model_id)
139140
return self
@@ -286,7 +287,7 @@ def _predict_and_retry(
286287
bpd.concat([df_result, df_succ]) if df_result is not None else df_succ
287288
)
288289

289-
df_result = cast(
290+
df_result = typing.cast(
290291
bpd.DataFrame,
291292
bpd.concat([df_result, df_fail]) if df_result is not None else df_fail,
292293
)
@@ -306,7 +307,7 @@ def _extract_output_names(self):
306307

307308
output_names = []
308309
for transform_col in self._bqml_model._model._properties["transformColumns"]:
309-
transform_col_dict = cast(dict, transform_col)
310+
transform_col_dict = typing.cast(dict, transform_col)
310311
# pass the columns that are not transformed
311312
if "transformSql" not in transform_col_dict:
312313
continue
Collapse file

‎bigframes/ml/compose.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/compose.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import re
2222
import types
2323
import typing
24-
from typing import cast, Iterable, List, Optional, Set, Tuple, Union
24+
from typing import Iterable, List, Optional, Set, Tuple, Union
2525

2626
from bigframes_vendored import constants
2727
import bigframes_vendored.sklearn.compose._column_transformer
@@ -218,7 +218,7 @@ def camel_to_snake(name):
218218

219219
output_names = []
220220
for transform_col in bq_model._properties["transformColumns"]:
221-
transform_col_dict = cast(dict, transform_col)
221+
transform_col_dict = typing.cast(dict, transform_col)
222222
# pass the columns that are not transformed
223223
if "transformSql" not in transform_col_dict:
224224
continue
@@ -282,7 +282,7 @@ def _merge(
282282
return self # SQLScalarColumnTransformer only work inside ColumnTransformer
283283
feature_columns_sorted = sorted(
284284
[
285-
cast(str, feature_column.name)
285+
typing.cast(str, feature_column.name)
286286
for feature_column in bq_model.feature_columns
287287
]
288288
)
Collapse file

‎bigframes/ml/core.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/core.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import dataclasses
2020
import datetime
21-
from typing import Callable, cast, Iterable, Mapping, Optional, Union
21+
import typing
22+
from typing import Callable, Iterable, Mapping, Optional, Union
2223
import uuid
2324

2425
from google.cloud import bigquery
@@ -376,7 +377,7 @@ def copy(self, new_model_name: str, replace: bool = False) -> BqmlModel:
376377
def register(self, vertex_ai_model_id: Optional[str] = None) -> BqmlModel:
377378
if vertex_ai_model_id is None:
378379
# vertex id needs to start with letters. https://cloud.google.com/vertex-ai/docs/general/resource-naming
379-
vertex_ai_model_id = "bigframes_" + cast(str, self._model.model_id)
380+
vertex_ai_model_id = "bigframes_" + typing.cast(str, self._model.model_id)
380381

381382
# truncate as Vertex ID only accepts 63 characters, easily exceeding the limit for temp models.
382383
# The possibility of conflicts should be low.
Collapse file

‎bigframes/ml/imported.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/imported.py
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from __future__ import annotations
1818

19-
from typing import cast, Mapping, Optional
19+
import typing
20+
from typing import Mapping, Optional
2021

2122
from google.cloud import bigquery
2223

@@ -78,7 +79,7 @@ def predict(self, X: utils.ArrayType) -> bpd.DataFrame:
7879
if self.model_path is None:
7980
raise ValueError("Model GCS path must be provided.")
8081
self._bqml_model = self._create_bqml_model()
81-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
82+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
8283

8384
(X,) = utils.batch_convert_to_dataframe(X)
8485

@@ -99,7 +100,7 @@ def to_gbq(self, model_name: str, replace: bool = False) -> TensorFlowModel:
99100
if self.model_path is None:
100101
raise ValueError("Model GCS path must be provided.")
101102
self._bqml_model = self._create_bqml_model()
102-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
103+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
103104

104105
new_model = self._bqml_model.copy(model_name, replace)
105106
return new_model.session.read_gbq_model(model_name)
@@ -157,7 +158,7 @@ def predict(self, X: utils.ArrayType) -> bpd.DataFrame:
157158
if self.model_path is None:
158159
raise ValueError("Model GCS path must be provided.")
159160
self._bqml_model = self._create_bqml_model()
160-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
161+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
161162

162163
(X,) = utils.batch_convert_to_dataframe(X, session=self._bqml_model.session)
163164

@@ -178,7 +179,7 @@ def to_gbq(self, model_name: str, replace: bool = False) -> ONNXModel:
178179
if self.model_path is None:
179180
raise ValueError("Model GCS path must be provided.")
180181
self._bqml_model = self._create_bqml_model()
181-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
182+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
182183

183184
new_model = self._bqml_model.copy(model_name, replace)
184185
return new_model.session.read_gbq_model(model_name)
@@ -276,7 +277,7 @@ def predict(self, X: utils.ArrayType) -> bpd.DataFrame:
276277
if self.model_path is None:
277278
raise ValueError("Model GCS path must be provided.")
278279
self._bqml_model = self._create_bqml_model()
279-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
280+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
280281

281282
(X,) = utils.batch_convert_to_dataframe(X, session=self._bqml_model.session)
282283

@@ -297,7 +298,7 @@ def to_gbq(self, model_name: str, replace: bool = False) -> XGBoostModel:
297298
if self.model_path is None:
298299
raise ValueError("Model GCS path must be provided.")
299300
self._bqml_model = self._create_bqml_model()
300-
self._bqml_model = cast(core.BqmlModel, self._bqml_model)
301+
self._bqml_model = typing.cast(core.BqmlModel, self._bqml_model)
301302

302303
new_model = self._bqml_model.copy(model_name, replace)
303304
return new_model.session.read_gbq_model(model_name)
Collapse file

‎bigframes/ml/llm.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/llm.py
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from __future__ import annotations
1818

19-
from typing import cast, Iterable, Literal, Mapping, Optional, Union
19+
import typing
20+
from typing import Iterable, Literal, Mapping, Optional, Union
2021
import warnings
2122

2223
import bigframes_vendored.constants as constants
@@ -252,7 +253,7 @@ def predict(
252253

253254
if len(X.columns) == 1:
254255
# BQML identified the column by name
255-
col_label = cast(blocks.Label, X.columns[0])
256+
col_label = typing.cast(blocks.Label, X.columns[0])
256257
X = X.rename(columns={col_label: "content"})
257258

258259
options: dict = {}
@@ -391,7 +392,7 @@ def predict(
391392

392393
if len(X.columns) == 1:
393394
# BQML identified the column by name
394-
col_label = cast(blocks.Label, X.columns[0])
395+
col_label = typing.cast(blocks.Label, X.columns[0])
395396
X = X.rename(columns={col_label: "content"})
396397

397398
# TODO(garrettwu): remove transform to ObjRefRuntime when BQML supports ObjRef as input
@@ -604,7 +605,10 @@ def fit(
604605
options["prompt_col"] = X.columns.tolist()[0]
605606

606607
self._bqml_model = self._bqml_model_factory.create_llm_remote_model(
607-
X, y, options=options, connection_name=cast(str, self.connection_name)
608+
X,
609+
y,
610+
options=options,
611+
connection_name=typing.cast(str, self.connection_name),
608612
)
609613
return self
610614

@@ -735,7 +739,7 @@ def predict(
735739

736740
if len(X.columns) == 1:
737741
# BQML identified the column by name
738-
col_label = cast(blocks.Label, X.columns[0])
742+
col_label = typing.cast(blocks.Label, X.columns[0])
739743
X = X.rename(columns={col_label: "prompt"})
740744

741745
options: dict = {
@@ -820,8 +824,8 @@ def score(
820824
)
821825

822826
# BQML identified the column by name
823-
X_col_label = cast(blocks.Label, X.columns[0])
824-
y_col_label = cast(blocks.Label, y.columns[0])
827+
X_col_label = typing.cast(blocks.Label, X.columns[0])
828+
y_col_label = typing.cast(blocks.Label, y.columns[0])
825829
X = X.rename(columns={X_col_label: "input_text"})
826830
y = y.rename(columns={y_col_label: "output_text"})
827831

@@ -1033,7 +1037,7 @@ def predict(
10331037

10341038
if len(X.columns) == 1:
10351039
# BQML identified the column by name
1036-
col_label = cast(blocks.Label, X.columns[0])
1040+
col_label = typing.cast(blocks.Label, X.columns[0])
10371041
X = X.rename(columns={col_label: "prompt"})
10381042

10391043
options = {
Collapse file

‎bigframes/ml/model_selection.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/model_selection.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import inspect
2121
from itertools import chain
2222
import time
23-
from typing import cast, Generator, List, Optional, Union
23+
import typing
24+
from typing import Generator, List, Optional, Union
2425

2526
import bigframes_vendored.sklearn.model_selection._split as vendored_model_selection_split
2627
import bigframes_vendored.sklearn.model_selection._validation as vendored_model_selection_validation
@@ -99,10 +100,10 @@ def _stratify_split(df: bpd.DataFrame, stratify: bpd.Series) -> List[bpd.DataFra
99100
train_dfs.append(train)
100101
test_dfs.append(test)
101102

102-
train_df = cast(
103+
train_df = typing.cast(
103104
bpd.DataFrame, bpd.concat(train_dfs).drop(columns="bigframes_stratify_col")
104105
)
105-
test_df = cast(
106+
test_df = typing.cast(
106107
bpd.DataFrame, bpd.concat(test_dfs).drop(columns="bigframes_stratify_col")
107108
)
108109
return [train_df, test_df]
Collapse file

‎bigframes/ml/preprocessing.py‎

Copy file name to clipboardExpand all lines: bigframes/ml/preprocessing.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from __future__ import annotations
1919

2020
import typing
21-
from typing import cast, Iterable, List, Literal, Optional, Union
21+
from typing import Iterable, List, Literal, Optional, Union
2222

2323
import bigframes_vendored.sklearn.preprocessing._data
2424
import bigframes_vendored.sklearn.preprocessing._discretization
@@ -470,7 +470,7 @@ def _parse_from_sql(cls, sql: str) -> tuple[OneHotEncoder, str]:
470470
s = sql[sql.find("(") + 1 : sql.find(")")]
471471
col_label, drop_str, top_k, frequency_threshold = s.split(", ")
472472
drop = (
473-
cast(Literal["most_frequent"], "most_frequent")
473+
typing.cast(Literal["most_frequent"], "most_frequent")
474474
if drop_str.lower() == "'most_frequent'"
475475
else None
476476
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.