Skip to content

Commit 9fee857

Browse files
authored
chore: type check with mypy --check-untyped-defs option (#693)
* chore: type check with mypy `--check-untyped-defs` option * add TODOs for tests/system/small/ml/test_metrics.py * add TODOs for tests/system/large/ml/test_cluster.py * add TODOs for tests/system/large/ml/test_decomposition.py * more TODOs * test_dataframe TODOs * tests/system/small/test_encryption.py TODOs * test_index TODOs * TODO test_index, test_multiindex * tests/system/small/test_pandas.py TODOs * test_series TODOs * more TODOs * tests/system/large/ml/test_ensemble.py TODOs * more TODOs * more TODOs * add final TODOs * add bug number
1 parent da9b136 commit 9fee857

33 files changed

+295
-152
lines changed

bigframes/core/blocks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,9 @@ def calculate_pairwise_metric(self, op=agg_ops.CorrOp()):
12261226
)
12271227
labels = self._get_labels_for_columns(self.value_columns)
12281228

1229+
# TODO(b/340896143): fix type error
12291230
expr = expr.unpivot(
1230-
row_labels=labels,
1231+
row_labels=labels, # type: ignore
12311232
index_col_ids=index_col_ids,
12321233
unpivot_columns=unpivot_columns,
12331234
)

bigframes/core/indexers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def __getitem__(self, key):
160160

161161
columns = key[1]
162162
if isinstance(columns, pd.Series) and columns.dtype == "bool":
163-
columns = df.columns[columns]
163+
# TODO(b/340892590): fix type error
164+
columns = df.columns[columns] # type: ignore
164165

165166
return df[columns]
166167

bigframes/core/indexes/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def __new__(
9191
from bigframes.core.indexes.multi import MultiIndex
9292

9393
klass = MultiIndex if len(block._index_columns) > 1 else cls
94-
result = typing.cast(Index, object.__new__(klass))
94+
# TODO(b/340893286): fix type error
95+
result = typing.cast(Index, object.__new__(klass)) # type: ignore
9596
result._query_job = None
9697
result._block = block
9798
return result

bigframes/dataframe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,8 @@ def label_filter(label):
17621762
if like:
17631763
return like in label_str
17641764
else: # regex
1765-
return re.match(regex, label_str) is not None
1765+
# TODO(b/340891296): fix type error
1766+
return re.match(regex, label_str) is not None # type: ignore
17661767

17671768
cols = [
17681769
col_id

bigframes/functions/remote_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,9 @@ def wrapper(f):
10231023
raise TypeError("f must be callable, got {}".format(f))
10241024

10251025
signature = inspect.signature(f)
1026+
# TODO(b/340898611): fix type error
10261027
ibis_signature = ibis_signature_from_python_signature(
1027-
signature, input_types, output_type
1028+
signature, input_types, output_type # type: ignore
10281029
)
10291030

10301031
remote_function_client = RemoteFunctionClient(

bigframes/operations/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ def output_type(self, *input_types):
491491
if self.to_type == pa.string():
492492
return dtypes.STRING_DTYPE
493493
if isinstance(self.to_type, str):
494-
return dtypes.BIGFRAMES_STRING_TO_BIGFRAMES[self.to_type]
494+
# TODO(b/340895446): fix type error
495+
return dtypes.BIGFRAMES_STRING_TO_BIGFRAMES[self.to_type] # type: ignore
495496
return self.to_type
496497

497498

@@ -513,7 +514,8 @@ class RemoteFunctionOp(UnaryOp):
513514

514515
def output_type(self, *input_types):
515516
# This property should be set to a valid Dtype by the @remote_function decorator or read_gbq_function method
516-
return self.func.output_dtype
517+
# TODO(b/340895446): fix type error
518+
return self.func.output_dtype # type: ignore
517519

518520

519521
@dataclasses.dataclass(frozen=True)
@@ -627,7 +629,8 @@ class BinaryRemoteFunctionOp(BinaryOp):
627629

628630
def output_type(self, *input_types):
629631
# This property should be set to a valid Dtype by the @remote_function decorator or read_gbq_function method
630-
return self.func.output_dtype
632+
# TODO(b/340895446): fix type error
633+
return self.func.output_dtype # type: ignore
631634

632635

633636
add_op = AddOp()

bigframes/operations/_matplotlib/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525

2626
def plot(data, kind, **kwargs):
27-
plot_obj = PLOT_CLASSES[kind](data, **kwargs)
27+
# TODO(b/340896123): fix type error
28+
plot_obj = PLOT_CLASSES[kind](data, **kwargs) # type: ignore
2829
plot_obj.generate()
2930
plot_obj.draw()
3031
return plot_obj.result

bigframes/operations/_matplotlib/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def draw(self) -> None:
3939

4040
@property
4141
def result(self):
42-
return self.axes
42+
# TODO(b/340896123): fix type error
43+
return self.axes # type: ignore
4344

4445

4546
class SamplingPlot(MPLPlot):

bigframes/session/clients.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ def __init__(
117117
def _create_bigquery_client(self):
118118
bq_options = None
119119
if self._use_regional_endpoints:
120+
# TODO(b/340896138): fix type error
120121
bq_options = google.api_core.client_options.ClientOptions(
121122
api_endpoint=(
122123
_BIGQUERY_REGIONAL_ENDPOINT
123-
if self._location.lower() in _REP_SUPPORTED_REGIONS
124+
if self._location.lower() in _REP_SUPPORTED_REGIONS # type: ignore
124125
else _BIGQUERY_LOCATIONAL_ENDPOINT
125126
).format(location=self._location),
126127
)
@@ -158,12 +159,11 @@ def bqconnectionclient(self):
158159
bqconnection_info = google.api_core.gapic_v1.client_info.ClientInfo(
159160
user_agent=self._application_name
160161
)
161-
self._bqconnectionclient = (
162-
google.cloud.bigquery_connection_v1.ConnectionServiceClient(
163-
client_info=bqconnection_info,
164-
client_options=bqconnection_options,
165-
credentials=self._credentials,
166-
)
162+
# TODO(b/340896138): fix type error
163+
self._bqconnectionclient = google.cloud.bigquery_connection_v1.ConnectionServiceClient( # type: ignore
164+
client_info=bqconnection_info,
165+
client_options=bqconnection_options,
166+
credentials=self._credentials,
167167
)
168168

169169
return self._bqconnectionclient
@@ -173,18 +173,20 @@ def bqstoragereadclient(self):
173173
if not self._bqstoragereadclient:
174174
bqstorage_options = None
175175
if self._use_regional_endpoints:
176+
# TODO(b/340896138): fix type error
176177
bqstorage_options = google.api_core.client_options.ClientOptions(
177178
api_endpoint=(
178179
_BIGQUERYSTORAGE_REGIONAL_ENDPOINT
179-
if self._location.lower() in _REP_SUPPORTED_REGIONS
180+
if self._location.lower() in _REP_SUPPORTED_REGIONS # type: ignore
180181
else _BIGQUERYSTORAGE_LOCATIONAL_ENDPOINT
181182
).format(location=self._location),
182183
)
183184
bqstorage_info = google.api_core.gapic_v1.client_info.ClientInfo(
184185
user_agent=self._application_name
185186
)
187+
# TODO(b/340896138): fix type error
186188
self._bqstoragereadclient = (
187-
google.cloud.bigquery_storage_v1.BigQueryReadClient(
189+
google.cloud.bigquery_storage_v1.BigQueryReadClient( # type: ignore
188190
client_info=bqstorage_info,
189191
client_options=bqstorage_options,
190192
credentials=self._credentials,
@@ -199,8 +201,9 @@ def cloudfunctionsclient(self):
199201
functions_info = google.api_core.gapic_v1.client_info.ClientInfo(
200202
user_agent=self._application_name
201203
)
204+
# TODO(b/340896138): fix type error
202205
self._cloudfunctionsclient = (
203-
google.cloud.functions_v2.FunctionServiceClient(
206+
google.cloud.functions_v2.FunctionServiceClient( # type: ignore
204207
client_info=functions_info,
205208
credentials=self._credentials,
206209
)
@@ -214,8 +217,9 @@ def resourcemanagerclient(self):
214217
resourcemanager_info = google.api_core.gapic_v1.client_info.ClientInfo(
215218
user_agent=self._application_name
216219
)
220+
# TODO(b/340896138): fix type error
217221
self._resourcemanagerclient = (
218-
google.cloud.resourcemanager_v3.ProjectsClient(
222+
google.cloud.resourcemanager_v3.ProjectsClient( # type: ignore
219223
credentials=self._credentials, client_info=resourcemanager_info
220224
)
221225
)

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def mypy(session):
248248
"bigframes",
249249
os.path.join("tests", "system"),
250250
os.path.join("tests", "unit"),
251+
"--check-untyped-defs",
251252
"--explicit-package-bases",
252253
'--exclude="^third_party"',
253254
)

0 commit comments

Comments
 (0)