Skip to content

Commit fbeffee

Browse files
committed
chore: adjusts type hints to account for complications with mypy
1 parent f90c49b commit fbeffee

File tree

8 files changed

+22
-13
lines changed

8 files changed

+22
-13
lines changed

packages/bigframes/bigframes/core/compile/ibis_compiler/aggregate_compiler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,9 @@ def _(
528528
column: ibis_types.Column,
529529
window=None,
530530
) -> ibis_types.Value:
531+
# Ibis FirstNonNullValue expects Value[Any, Columnar], Mypy struggles to see Column as compatible.
531532
return _apply_window_if_present(
532-
ibis_ops.FirstNonNullValue(column).to_expr(),
533+
ibis_ops.FirstNonNullValue(column).to_expr(), # type: ignore[arg-type]
533534
window, # type: ignore
534535
)
535536

@@ -549,8 +550,9 @@ def _(
549550
column: ibis_types.Column,
550551
window=None,
551552
) -> ibis_types.Value:
553+
# Ibis LastNonNullValue expects Value[Any, Columnar], Mypy struggles to see Column as compatible.
552554
return _apply_window_if_present(
553-
ibis_ops.LastNonNullValue(column).to_expr(),
555+
ibis_ops.LastNonNullValue(column).to_expr(), # type: ignore[arg-type]
554556
window, # type: ignore
555557
)
556558

@@ -803,8 +805,9 @@ def _to_ibis_boundary(
803805
) -> Optional[ibis_expr_window.WindowBoundary]:
804806
if boundary is None:
805807
return None
808+
# WindowBoundary expects Value[Any, Any], ibis_types.literal returns Scalar which Mypy doesn't see as compatible.
806809
return ibis_expr_window.WindowBoundary(
807-
abs(boundary),
810+
ibis_types.literal(boundary if boundary >= 0 else -boundary), # type: ignore[arg-type]
808811
preceding=boundary <= 0, # type:ignore
809812
)
810813

packages/bigframes/bigframes/core/compile/ibis_compiler/operations/geo_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def st_buffer(
182182

183183
@ibis_udf.scalar.builtin
184184
def st_distance(
185-
a: ibis_dtypes.geography, b: ibis_dtypes.geography, use_spheroid: bool
185+
a: ibis_dtypes.geography, b: ibis_dtypes.geography, use_spheroid: bool # type: ignore
186186
) -> ibis_dtypes.float: # type: ignore
187187
"""Convert string to geography."""
188188

packages/bigframes/bigframes/core/compile/ibis_compiler/scalar_op_registry.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,9 +2168,12 @@ def obj_make_ref_json(objectref_json: ibis_dtypes.JSON) -> _OBJ_REF_IBIS_DTYPE:
21682168

21692169

21702170
@ibis_udf.scalar.builtin(name="OBJ.GET_ACCESS_URL")
2171-
def obj_get_access_url(
2172-
obj_ref: _OBJ_REF_IBIS_DTYPE, mode: ibis_dtypes.String
2173-
) -> ibis_dtypes.JSON: # type: ignore
2171+
# Stub for BigQuery UDF, empty body is intentional.
2172+
# _OBJ_REF_IBIS_DTYPE is a variable holding a type, Mypy complains about it being used as type hint.
2173+
def obj_get_access_url( # type: ignore[empty-body]
2174+
obj_ref: _OBJ_REF_IBIS_DTYPE, # type: ignore[valid-type]
2175+
mode: ibis_dtypes.String
2176+
) -> ibis_dtypes.JSON:
21742177
"""Get access url (as ObjectRefRumtime JSON) from ObjectRef."""
21752178

21762179

packages/bigframes/bigframes/core/expression_factoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def factor_aggregation(root: nodes.ColumnDef) -> FactoredAggregation:
243243
}
244244

245245
root_scalar_expr = nodes.ColumnDef(
246-
sub_expressions(root.expression, agg_outputs_dict),
246+
sub_expressions(root.expression, cast(Mapping[expression.Expression, expression.Expression], agg_outputs_dict)),
247247
root.id, # type: ignore
248248
)
249249

packages/bigframes/bigframes/core/local_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import bigframes.core.schema as schemata
3535
import bigframes.dtypes
36+
from bigframes.core import identifiers
3637
from bigframes.core import pyarrow_utils
3738

3839

packages/bigframes/bigframes/core/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def fields(self) -> Sequence[Field]:
674674
Field(
675675
col_id,
676676
self.local_data_source.schema.get_type(source_id),
677-
nullable=self.local_data_source.is_nullable(source_id),
677+
nullable=self.local_data_source.is_nullable(identifiers.ColumnId(source_id)),
678678
)
679679
for col_id, source_id in self.scan_list.items
680680
)

packages/bigframes/bigframes/core/rewrite/as_sql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,9 @@ def _extract_ctes_to_with_expr(
291291
root.top_down(lambda x: mapping.get(x, x)),
292292
cte_names,
293293
tuple(
294-
cte_node.child.top_down(lambda x: mapping.get(x, x))
295-
for cte_node in topological_ctes # type: ignore
294+
# Mypy loses context that cte_node is a CteNode with a child attribute, despite the isinstance filter above.
295+
cte_node.child.top_down(lambda x: mapping.get(x, x)) # type: ignore[attr-defined]
296+
for cte_node in topological_ctes
296297
),
297298
)
298299

packages/bigframes/bigframes/session/iceberg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ def _extract_location_from_catalog_extension_data(data):
9898

9999

100100
class SchemaVisitor(pyiceberg.schema.SchemaVisitorPerPrimitiveType[bq.SchemaField]):
101-
def schema(
101+
# Override returns a tuple of fields instead of a single field, violating supertype signature but intentional for this visitor.
102+
def schema( # type: ignore[override]
102103
self, schema: pyiceberg.schema.Schema, struct_result: bq.SchemaField
103-
) -> tuple[bq.SchemaField, ...]: # type: ignore
104+
) -> tuple[bq.SchemaField, ...]:
104105
return tuple(f for f in struct_result.fields)
105106

106107
def struct(

0 commit comments

Comments
 (0)