Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 421d24d

Browse files
authoredDec 2, 2024
chore: vendor ibis codes and remove ibis dependency (#1170)
1 parent faa2738 commit 421d24d

File tree

122 files changed

+45890
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+45890
-438
lines changed
 

‎.github/ISSUE_TEMPLATE/bug_report.md

-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ If you are still having issues, please be sure to include as much information as
2727
import sys
2828
import bigframes
2929
import google.cloud.bigquery
30-
import ibis
3130
import pandas
3231
import pyarrow
3332
import sqlglot
3433

3534
print(f"Python: {sys.version}")
3635
print(f"bigframes=={bigframes.__version__}")
3736
print(f"google-cloud-bigquery=={google.cloud.bigquery.__version__}")
38-
print(f"ibis=={ibis.__version__}")
3937
print(f"pandas=={pandas.__version__}")
4038
print(f"pyarrow=={pyarrow.__version__}")
4139
print(f"sqlglot=={sqlglot.__version__}")

‎bigframes/core/compile/aggregate_compiler.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from typing import cast, List, Optional
2020

2121
import bigframes_vendored.constants as constants
22-
import bigframes_vendored.ibis.expr.operations as vendored_ibis_ops
23-
import ibis
24-
import ibis.expr.datatypes as ibis_dtypes
25-
import ibis.expr.operations as ibis_ops
26-
import ibis.expr.types as ibis_types
22+
import bigframes_vendored.ibis.expr.api as ibis_api
23+
import bigframes_vendored.ibis.expr.datatypes as ibis_dtypes
24+
import bigframes_vendored.ibis.expr.operations as ibis_ops
25+
import bigframes_vendored.ibis.expr.operations.udf as ibis_udf
26+
import bigframes_vendored.ibis.expr.types as ibis_types
2727
import pandas as pd
2828

2929
import bigframes.core.compile.ibis_types as compile_ibis_types
@@ -37,7 +37,7 @@
3737

3838
# TODO(swast): We can remove this if ibis adds general approx_quantile
3939
# See: https://github.com/ibis-project/ibis/issues/9541
40-
@ibis.udf.agg.builtin
40+
@ibis_udf.agg.builtin
4141
def approx_quantiles(expression: float, number) -> List[float]:
4242
"""APPROX_QUANTILES
4343
@@ -56,13 +56,13 @@ def compile_aggregate(
5656
if isinstance(aggregate, ex.UnaryAggregation):
5757
input = scalar_compiler.compile_expression(aggregate.arg, bindings=bindings)
5858
if aggregate.op.can_order_by:
59-
return compile_ordered_unary_agg(aggregate.op, input, order_by=order_by)
59+
return compile_ordered_unary_agg(aggregate.op, input, order_by=order_by) # type: ignore
6060
else:
61-
return compile_unary_agg(aggregate.op, input)
61+
return compile_unary_agg(aggregate.op, input) # type: ignore
6262
elif isinstance(aggregate, ex.BinaryAggregation):
6363
left = scalar_compiler.compile_expression(aggregate.left, bindings=bindings)
6464
right = scalar_compiler.compile_expression(aggregate.right, bindings=bindings)
65-
return compile_binary_agg(aggregate.op, left, right)
65+
return compile_binary_agg(aggregate.op, left, right) # type: ignore
6666
else:
6767
raise ValueError(f"Unexpected aggregation: {aggregate}")
6868

@@ -76,7 +76,7 @@ def compile_analytic(
7676
return compile_nullary_agg(aggregate.op, window)
7777
elif isinstance(aggregate, ex.UnaryAggregation):
7878
input = scalar_compiler.compile_expression(aggregate.arg, bindings=bindings)
79-
return compile_unary_agg(aggregate.op, input, window)
79+
return compile_unary_agg(aggregate.op, input, window) # type: ignore
8080
elif isinstance(aggregate, ex.BinaryAggregation):
8181
raise NotImplementedError("binary analytic operations not yet supported")
8282
else:
@@ -147,7 +147,7 @@ def constrained_op(
147147

148148
@compile_nullary_agg.register
149149
def _(op: agg_ops.SizeOp, window=None) -> ibis_types.NumericValue:
150-
return _apply_window_if_present(vendored_ibis_ops.count(1), window)
150+
return _apply_window_if_present(ibis_ops.count(1), window)
151151

152152

153153
@compile_unary_agg.register
@@ -160,7 +160,7 @@ def _(
160160
# Will be null if all inputs are null. Pandas defaults to zero sum though.
161161
bq_sum = _apply_window_if_present(column.sum(), window)
162162
return (
163-
ibis.case().when(bq_sum.isnull(), ibis_types.literal(0)).else_(bq_sum).end() # type: ignore
163+
ibis_api.case().when(bq_sum.isnull(), ibis_types.literal(0)).else_(bq_sum).end() # type: ignore
164164
)
165165

166166

@@ -217,15 +217,15 @@ def _(
217217
def approx_top_count(expression, number: ibis_dtypes.int64): # type: ignore
218218
...
219219

220-
return_type = ibis_dtypes.Array(
221-
ibis_dtypes.Struct.from_tuples(
220+
ibis_return_type = ibis_dtypes.Array(
221+
value_type=ibis_dtypes.Struct.from_tuples(
222222
[("value", column.type()), ("count", ibis_dtypes.int64)]
223223
)
224-
)
225-
approx_top_count.__annotations__["return"] = return_type
224+
) # type: ignore
225+
approx_top_count.__annotations__["return"] = ibis_return_type
226226
udf_op = ibis_ops.udf.agg.builtin(approx_top_count)
227227

228-
return udf_op(expression=column, number=op.number)
228+
return udf_op(expression=column, number=op.number) # type: ignore
229229

230230

231231
@compile_unary_agg.register
@@ -263,29 +263,29 @@ def _(
263263
# apply power after. Note, log and power base must be equal! This impl uses base 2.
264264
logs = cast(
265265
ibis_types.NumericColumn,
266-
ibis.case().when(is_zero, 0).else_(column.abs().log2()).end(),
266+
ibis_api.case().when(is_zero, 0).else_(column.abs().log2()).end(),
267267
)
268268
logs_sum = _apply_window_if_present(logs.sum(), window)
269269
magnitude = cast(ibis_types.NumericValue, ibis_types.literal(2)).pow(logs_sum)
270270

271271
# Can't determine sign from logs, so have to determine parity of count of negative inputs
272272
is_negative = cast(
273273
ibis_types.NumericColumn,
274-
ibis.case().when(column.sign() == -1, 1).else_(0).end(),
274+
ibis_api.case().when(column.sign() == -1, 1).else_(0).end(),
275275
)
276276
negative_count = _apply_window_if_present(is_negative.sum(), window)
277277
negative_count_parity = negative_count % cast(
278-
ibis_types.NumericValue, ibis.literal(2)
278+
ibis_types.NumericValue, ibis_types.literal(2)
279279
) # 1 if result should be negative, otherwise 0
280280

281281
any_zeroes = _apply_window_if_present(is_zero.any(), window)
282282
float_result = (
283-
ibis.case()
283+
ibis_api.case()
284284
.when(any_zeroes, ibis_types.literal(0))
285285
.else_(magnitude * pow(-1, negative_count_parity))
286286
.end()
287287
)
288-
return float_result
288+
return cast(ibis_types.NumericValue, float_result)
289289

290290

291291
@compile_unary_agg.register
@@ -353,7 +353,7 @@ def _(
353353
x: ibis_types.Column,
354354
window=None,
355355
):
356-
out = ibis.case()
356+
out = ibis_api.case()
357357
if isinstance(op.bins, int):
358358
col_min = _apply_window_if_present(x.min(), window)
359359
col_max = _apply_window_if_present(x.max(), window)
@@ -376,7 +376,7 @@ def _(
376376
col_min + this_bin * bin_width - (0 if this_bin > 0 else adj)
377377
)
378378
right_edge = col_min + (this_bin + 1) * bin_width
379-
interval_struct = ibis.struct(
379+
interval_struct = ibis_types.struct(
380380
{
381381
"left_exclusive": left_edge,
382382
"right_inclusive": right_edge,
@@ -395,7 +395,7 @@ def _(
395395
left = compile_ibis_types.literal_to_ibis_scalar(interval[0])
396396
right = compile_ibis_types.literal_to_ibis_scalar(interval[1])
397397
condition = (x > left) & (x <= right)
398-
interval_struct = ibis.struct(
398+
interval_struct = ibis_types.struct(
399399
{"left_exclusive": left, "right_inclusive": right}
400400
)
401401
out = out.when(condition, interval_struct)
@@ -422,7 +422,7 @@ def _(
422422
ibis_types.FloatingColumn,
423423
_apply_window_if_present(column.percent_rank(), window),
424424
)
425-
out = ibis.case()
425+
out = ibis_api.case()
426426
first_ibis_quantile = compile_ibis_types.literal_to_ibis_scalar(
427427
self.quantiles[0]
428428
)
@@ -466,7 +466,7 @@ def _(
466466
window=None,
467467
) -> ibis_types.IntegerValue:
468468
# Ibis produces 0-based ranks, while pandas creates 1-based ranks
469-
return _apply_window_if_present(ibis.rank(), window) + 1
469+
return _apply_window_if_present(ibis_api.rank(), window) + 1
470470

471471

472472
@compile_unary_agg.register
@@ -491,7 +491,7 @@ def _(
491491
window=None,
492492
) -> ibis_types.Value:
493493
return _apply_window_if_present(
494-
vendored_ibis_ops.FirstNonNullValue(column).to_expr(), window # type: ignore
494+
ibis_ops.FirstNonNullValue(column).to_expr(), window # type: ignore
495495
)
496496

497497

@@ -511,7 +511,7 @@ def _(
511511
window=None,
512512
) -> ibis_types.Value:
513513
return _apply_window_if_present(
514-
vendored_ibis_ops.LastNonNullValue(column).to_expr(), window # type: ignore
514+
ibis_ops.LastNonNullValue(column).to_expr(), window # type: ignore
515515
)
516516

517517

@@ -602,9 +602,9 @@ def _(
602602
f"ArrayAgg with windowing is not supported. {constants.FEEDBACK_LINK}"
603603
)
604604

605-
return vendored_ibis_ops.ArrayAggregate(
606-
column,
607-
order_by=order_by,
605+
return ibis_ops.ArrayAggregate(
606+
column, # type: ignore
607+
order_by=order_by, # type: ignore
608608
).to_expr()
609609

610610

@@ -641,8 +641,9 @@ def _apply_window_if_present(value: ibis_types.Value, window):
641641
def _map_to_literal(
642642
original: ibis_types.Value, literal: ibis_types.Scalar
643643
) -> ibis_types.Column:
644-
# Hack required to perform aggregations on literals in ibis, even though bigquery will let you directly aggregate literals (eg. 'SELECT COUNT(1) from table1')
645-
return ibis.ifelse(original.isnull(), literal, literal) # type: ignore
644+
# Hack required to perform aggregations on literals in ibis, even though bigquery
645+
# will let you directly aggregate literals (eg. 'SELECT COUNT(1) from table1')
646+
return ibis_api.ifelse(original.isnull(), literal, literal) # type: ignore
646647

647648

648649
def _ibis_num(number: float):
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.