Skip to content

Commit 1b711aa

Browse files
committed
fix circular imports
1 parent 92870fd commit 1b711aa

File tree

12 files changed

+2257
-2172
lines changed

12 files changed

+2257
-2172
lines changed

bigframes/core/array_value.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
from bigframes.core.window_spec import WindowSpec
3838
import bigframes.dtypes
3939
import bigframes.exceptions as bfe
40-
import bigframes.operations as ops
41-
import bigframes.operations.aggregations as agg_ops
4240

4341
if typing.TYPE_CHECKING:
42+
# Avoid circular imports.
43+
import bigframes.operations.aggregations as agg_ops
4444
from bigframes.session import Session
4545

4646
ORDER_ID_COLUMN = "bigframes_ordering_id"
@@ -185,6 +185,8 @@ def get_column_type(self, key: str) -> bigframes.dtypes.Dtype:
185185

186186
def row_count(self) -> ArrayValue:
187187
"""Get number of rows in ArrayValue as a single-entry ArrayValue."""
188+
import bigframes.operations.aggregations as agg_ops # Avoid circular imports.
189+
188190
return ArrayValue(
189191
nodes.AggregateNode(
190192
child=self.node,
@@ -200,6 +202,8 @@ def row_count(self) -> ArrayValue:
200202
# Operations
201203
def filter_by_id(self, predicate_id: str, keep_null: bool = False) -> ArrayValue:
202204
"""Filter the table on a given expression, the predicate must be a boolean series aligned with the table expression."""
205+
import bigframes.operations as ops # Avoid circular imports.
206+
203207
predicate: ex.Expression = ex.deref(predicate_id)
204208
if keep_null:
205209
predicate = ops.fillna_op.as_expr(predicate, ex.const(True))

bigframes/core/compile/compiled.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import bigframes.core.compile.googlesql
3535
import bigframes.core.compile.ibis_types
3636
import bigframes.core.compile.scalar_op_compiler as op_compilers
37-
import bigframes.core.compile.scalar_op_compiler as scalar_op_compiler
3837
import bigframes.core.expression as ex
3938
from bigframes.core.ordering import OrderingExpression
4039
import bigframes.core.sql
@@ -45,6 +44,12 @@
4544
op_compiler = op_compilers.scalar_op_compiler
4645

4746

47+
# This must be the last import. Currently depending on side-effects.
48+
# TODO(tswast): Refactor all ops to register in the same file as where they are
49+
# defined so we don't need this.
50+
import bigframes.core.compile.scalar_op_registry # noqa: F401,E402
51+
52+
4853
# Ibis Implementations
4954
class UnorderedIR:
5055
def __init__(
@@ -679,13 +684,15 @@ def _join_condition(
679684

680685

681686
def _as_groupable(value: ibis_types.Value):
687+
from bigframes.core.compile import scalar_op_registry
688+
682689
# Some types need to be converted to another type to enable groupby
683690
if value.type().is_float64():
684691
return value.cast(ibis_dtypes.str)
685692
elif value.type().is_geospatial():
686693
return typing.cast(ibis_types.GeoSpatialColumn, value).as_binary()
687694
elif value.type().is_json():
688-
return scalar_op_compiler.to_json_string(value)
695+
return scalar_op_registry.to_json_string(value)
689696
else:
690697
return value
691698

bigframes/core/compile/compiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import bigframes.core.compile.concat as concat_impl
3030
import bigframes.core.compile.configs as configs
3131
import bigframes.core.compile.explode
32-
import bigframes.core.compile.scalar_op_compiler as compile_scalar
3332
import bigframes.core.nodes as nodes
3433
import bigframes.core.ordering as bf_ordering
3534
import bigframes.core.rewrite as rewrites
@@ -178,6 +177,8 @@ def compile_readlocal(node: nodes.ReadLocalNode, *args):
178177

179178
@_compile_node.register
180179
def compile_readtable(node: nodes.ReadTableNode, *args):
180+
from bigframes.core.compile import scalar_op_registry
181+
181182
ibis_table = _table_to_ibis(
182183
node.source, scan_cols=[col.source_id for col in node.scan_list.items]
183184
)
@@ -188,7 +189,7 @@ def compile_readtable(node: nodes.ReadTableNode, *args):
188189
scan_item.dtype == dtypes.JSON_DTYPE
189190
and ibis_table[scan_item.source_id].type() == ibis_dtypes.string
190191
):
191-
json_column = compile_scalar.parse_json(
192+
json_column = scalar_op_registry.parse_json(
192193
ibis_table[scan_item.source_id]
193194
).name(scan_item.source_id)
194195
ibis_table = ibis_table.mutate(json_column)

bigframes/core/compile/polars/compiler.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,6 @@ def _(self, op: ops.ScalarOp, input: pl.Expr) -> pl.Expr:
262262
# eg. We want "True" instead of "true" for bool to strin
263263
return input.cast(_DTYPE_MAPPING[op.to_type], strict=not op.safe)
264264

265-
# Register ops from other modules
266-
from bigframes.operations import IsNullOp, NotNullOp
267-
from bigframes.operations.isnull_op import (
268-
_polars_isnull_op_impl,
269-
_polars_notnull_op_impl,
270-
)
271-
272-
PolarsExpressionCompiler.compile_op.register(IsNullOp, _polars_isnull_op_impl)
273-
PolarsExpressionCompiler.compile_op.register(NotNullOp, _polars_notnull_op_impl)
274-
275265
@dataclasses.dataclass(frozen=True)
276266
class PolarsAggregateCompiler:
277267
scalar_compiler = PolarsExpressionCompiler()

0 commit comments

Comments
 (0)