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

chore: vendor ibis codes and remove ibis dependency #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
392e83a
chore: vendor ibis.common.exceptions
chelsea-lin Nov 22, 2024
6b3ffe2
chore: vendor ibis.common.collections
chelsea-lin Nov 22, 2024
6516629
chore: vendor ibis.common.bases
chelsea-lin Nov 22, 2024
4222877
chore: vendor ibis.common.typing
chelsea-lin Nov 22, 2024
4f08e3f
chore: vendor ibis.common.caching
chelsea-lin Nov 22, 2024
d6e2aa6
chore: vendor ibis.common.patterns and graph
chelsea-lin Nov 22, 2024
6eef495
chore: vendor ibis.util
chelsea-lin Nov 22, 2024
5374714
chore: vendor ibis.common.annotations
chelsea-lin Nov 23, 2024
e8aac1c
chore: vendor ibis.common.grounds
chelsea-lin Nov 23, 2024
f95f0c3
chore: vendor ibis.common.deferred
chelsea-lin Nov 23, 2024
6d298df
chore: vendor ibis.common.temporal
chelsea-lin Nov 23, 2024
563a4c7
chore: vendor ibis.common.dispatch
chelsea-lin Nov 23, 2024
1e5028c
fix: TypeError: unhashable type: Deferred
chelsea-lin Nov 23, 2024
c83c3eb
chore: vendor ibis.config
chelsea-lin Nov 23, 2024
6fe5970
chore: vendor ibis.expr.operations.udf
chelsea-lin Nov 23, 2024
2e6cf8f
chore: vendor ibis.backends.sql.datatypes
chelsea-lin Nov 23, 2024
f5ba81c
chore: vendor ibis.formats
chelsea-lin Nov 23, 2024
19bc7df
remove execute method from ibis.backends.bigquery.backend
chelsea-lin Nov 23, 2024
a016851
chore: vendor ibis.expr.operations.reductions and ibis.expr.operation…
chelsea-lin Nov 23, 2024
0fed812
vendor ibis.expr.rules
chelsea-lin Nov 23, 2024
3e8cbfa
vendor ibis.expr.schema
chelsea-lin Nov 23, 2024
0789273
vendor ibis.expr.operations.*
chelsea-lin Nov 23, 2024
1877297
import from ibis_dtypes rather than ibis
chelsea-lin Nov 22, 2024
4be9b48
fix lint
chelsea-lin Nov 25, 2024
e20a3e9
vendor ibis.backends.bigquery and ibis.backends.sql.compiler.bigquery
chelsea-lin Nov 25, 2024
077a36d
vendor ibis.formats for backend.execute's BigQueryPandasData
chelsea-lin Nov 25, 2024
084693c
import bigframes_vendored
chelsea-lin Nov 25, 2024
053bb73
vendor ibis.expr.datatypes
chelsea-lin Nov 25, 2024
7860f66
vendor ibis.expr.types
chelsea-lin Nov 25, 2024
048ffc2
minor fixes
chelsea-lin Nov 25, 2024
a817c92
add ibis.backends.bigquery.udf and missed import
chelsea-lin Nov 25, 2024
23f8868
vendor ibis.expr.api and ibis.expr.sql etc
chelsea-lin Nov 25, 2024
9008f90
fix lint
chelsea-lin Nov 25, 2024
a19baf7
fix unit tests
chelsea-lin Nov 25, 2024
0280ad4
fix mypy 110 errors
chelsea-lin Nov 27, 2024
6716430
remove ibis dependency
chelsea-lin Nov 27, 2024
86dd87f
fix unit-3.9 for ibis python 3.9 compatiable
chelsea-lin Nov 27, 2024
3bfae10
fix doctests: missing struct ops and public ToJsonString method
chelsea-lin Nov 27, 2024
765edd3
fix split
chelsea-lin Nov 28, 2024
0fa2249
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions 2 .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ If you are still having issues, please be sure to include as much information as
import sys
import bigframes
import google.cloud.bigquery
import ibis
import pandas
import pyarrow
import sqlglot

print(f"Python: {sys.version}")
print(f"bigframes=={bigframes.__version__}")
print(f"google-cloud-bigquery=={google.cloud.bigquery.__version__}")
print(f"ibis=={ibis.__version__}")
print(f"pandas=={pandas.__version__}")
print(f"pyarrow=={pyarrow.__version__}")
print(f"sqlglot=={sqlglot.__version__}")
Expand Down
69 changes: 35 additions & 34 deletions 69 bigframes/core/compile/aggregate_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from typing import cast, List, Optional

import bigframes_vendored.constants as constants
import bigframes_vendored.ibis.expr.operations as vendored_ibis_ops
import ibis
import ibis.expr.datatypes as ibis_dtypes
import ibis.expr.operations as ibis_ops
import ibis.expr.types as ibis_types
import bigframes_vendored.ibis.expr.api as ibis_api
import bigframes_vendored.ibis.expr.datatypes as ibis_dtypes
import bigframes_vendored.ibis.expr.operations as ibis_ops
import bigframes_vendored.ibis.expr.operations.udf as ibis_udf
import bigframes_vendored.ibis.expr.types as ibis_types
import pandas as pd

import bigframes.core.compile.ibis_types as compile_ibis_types
Expand All @@ -37,7 +37,7 @@

# TODO(swast): We can remove this if ibis adds general approx_quantile
# See: https://github.com/ibis-project/ibis/issues/9541
@ibis.udf.agg.builtin
@ibis_udf.agg.builtin
def approx_quantiles(expression: float, number) -> List[float]:
"""APPROX_QUANTILES

Expand All @@ -56,13 +56,13 @@ def compile_aggregate(
if isinstance(aggregate, ex.UnaryAggregation):
input = scalar_compiler.compile_expression(aggregate.arg, bindings=bindings)
if aggregate.op.can_order_by:
return compile_ordered_unary_agg(aggregate.op, input, order_by=order_by)
return compile_ordered_unary_agg(aggregate.op, input, order_by=order_by) # type: ignore
else:
return compile_unary_agg(aggregate.op, input)
return compile_unary_agg(aggregate.op, input) # type: ignore
elif isinstance(aggregate, ex.BinaryAggregation):
left = scalar_compiler.compile_expression(aggregate.left, bindings=bindings)
right = scalar_compiler.compile_expression(aggregate.right, bindings=bindings)
return compile_binary_agg(aggregate.op, left, right)
return compile_binary_agg(aggregate.op, left, right) # type: ignore
else:
raise ValueError(f"Unexpected aggregation: {aggregate}")

Expand All @@ -76,7 +76,7 @@ def compile_analytic(
return compile_nullary_agg(aggregate.op, window)
elif isinstance(aggregate, ex.UnaryAggregation):
input = scalar_compiler.compile_expression(aggregate.arg, bindings=bindings)
return compile_unary_agg(aggregate.op, input, window)
return compile_unary_agg(aggregate.op, input, window) # type: ignore
elif isinstance(aggregate, ex.BinaryAggregation):
raise NotImplementedError("binary analytic operations not yet supported")
else:
Expand Down Expand Up @@ -147,7 +147,7 @@ def constrained_op(

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


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


Expand Down Expand Up @@ -217,15 +217,15 @@ def _(
def approx_top_count(expression, number: ibis_dtypes.int64): # type: ignore
...

return_type = ibis_dtypes.Array(
ibis_dtypes.Struct.from_tuples(
ibis_return_type = ibis_dtypes.Array(
value_type=ibis_dtypes.Struct.from_tuples(
[("value", column.type()), ("count", ibis_dtypes.int64)]
)
)
approx_top_count.__annotations__["return"] = return_type
) # type: ignore
approx_top_count.__annotations__["return"] = ibis_return_type
udf_op = ibis_ops.udf.agg.builtin(approx_top_count)

return udf_op(expression=column, number=op.number)
return udf_op(expression=column, number=op.number) # type: ignore


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

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

any_zeroes = _apply_window_if_present(is_zero.any(), window)
float_result = (
ibis.case()
ibis_api.case()
.when(any_zeroes, ibis_types.literal(0))
.else_(magnitude * pow(-1, negative_count_parity))
.end()
)
return float_result
return cast(ibis_types.NumericValue, float_result)


@compile_unary_agg.register
Expand Down Expand Up @@ -353,7 +353,7 @@ def _(
x: ibis_types.Column,
window=None,
):
out = ibis.case()
out = ibis_api.case()
if isinstance(op.bins, int):
col_min = _apply_window_if_present(x.min(), window)
col_max = _apply_window_if_present(x.max(), window)
Expand All @@ -376,7 +376,7 @@ def _(
col_min + this_bin * bin_width - (0 if this_bin > 0 else adj)
)
right_edge = col_min + (this_bin + 1) * bin_width
interval_struct = ibis.struct(
interval_struct = ibis_types.struct(
{
"left_exclusive": left_edge,
"right_inclusive": right_edge,
Expand All @@ -395,7 +395,7 @@ def _(
left = compile_ibis_types.literal_to_ibis_scalar(interval[0])
right = compile_ibis_types.literal_to_ibis_scalar(interval[1])
condition = (x > left) & (x <= right)
interval_struct = ibis.struct(
interval_struct = ibis_types.struct(
{"left_exclusive": left, "right_inclusive": right}
)
out = out.when(condition, interval_struct)
Expand All @@ -422,7 +422,7 @@ def _(
ibis_types.FloatingColumn,
_apply_window_if_present(column.percent_rank(), window),
)
out = ibis.case()
out = ibis_api.case()
first_ibis_quantile = compile_ibis_types.literal_to_ibis_scalar(
self.quantiles[0]
)
Expand Down Expand Up @@ -466,7 +466,7 @@ def _(
window=None,
) -> ibis_types.IntegerValue:
# Ibis produces 0-based ranks, while pandas creates 1-based ranks
return _apply_window_if_present(ibis.rank(), window) + 1
return _apply_window_if_present(ibis_api.rank(), window) + 1


@compile_unary_agg.register
Expand All @@ -491,7 +491,7 @@ def _(
window=None,
) -> ibis_types.Value:
return _apply_window_if_present(
vendored_ibis_ops.FirstNonNullValue(column).to_expr(), window # type: ignore
ibis_ops.FirstNonNullValue(column).to_expr(), window # type: ignore
)


Expand All @@ -511,7 +511,7 @@ def _(
window=None,
) -> ibis_types.Value:
return _apply_window_if_present(
vendored_ibis_ops.LastNonNullValue(column).to_expr(), window # type: ignore
ibis_ops.LastNonNullValue(column).to_expr(), window # type: ignore
)


Expand Down Expand Up @@ -602,9 +602,9 @@ def _(
f"ArrayAgg with windowing is not supported. {constants.FEEDBACK_LINK}"
)

return vendored_ibis_ops.ArrayAggregate(
column,
order_by=order_by,
return ibis_ops.ArrayAggregate(
column, # type: ignore
order_by=order_by, # type: ignore
).to_expr()


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


def _ibis_num(number: float):
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.