Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c2009ed
docs: link to ML.EVALUATE BQML page for score() methods
ashleyxuu Oct 24, 2023
09ad5e4
feat: label query job with bigframes-api-xx using decorator
ashleyxuu Oct 25, 2023
4f4eb9b
reorganize the commit
ashleyxuu Oct 25, 2023
9ee937c
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Oct 26, 2023
272f0af
test: Log slowest tests durations (#146)
shobsi Oct 26, 2023
0e4c49c
docs: link to ML.EVALUATE BQML page for score() methods (#137)
ashleyxuu Oct 26, 2023
aad2c1a
feat: populate ibis version in user agent (#140)
ashleyxuu Oct 26, 2023
1043d6d
fix: don't override the global logging config (#138)
tswast Oct 26, 2023
1f49ef9
fix: use indexee's session for loc listlike cases (#152)
milkshakeiii Oct 26, 2023
c4c1e6e
feat: add pandas.qcut (#104)
TrevorBergeron Oct 26, 2023
4a27f44
feat: add unstack to series, add level param (#115)
TrevorBergeron Oct 26, 2023
fface57
feat: add `DataFrame.to_pandas_batches()` to download large `DataFram…
tswast Oct 26, 2023
bbc3c69
fix: resolve plotly rendering issue by using ipython html for job pro…
orrbradford Oct 26, 2023
a99d62c
refactor: ArrayValue is now a tree that defers conversion to ibis (#110)
TrevorBergeron Oct 27, 2023
f37d0b0
fix: fix bug with column names under repeated column assignment (#150)
milkshakeiii Oct 27, 2023
aba301c
test: refactor remote function tests (#147)
shobsi Oct 27, 2023
53bb2cd
feat: add dataframe melt (#116)
TrevorBergeron Oct 28, 2023
2bf4bcc
docs: add artithmetic df sample code (#153)
ashleyxuu Oct 30, 2023
343414a
feat: Implement operator `@` for `DataFrame.dot` (#139)
shobsi Oct 30, 2023
4eac10d
fix: fix typo and address comments
ashleyxuu Oct 30, 2023
868d2ad
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Oct 30, 2023
c03a8d9
Merge branch 'main' into ashleyxu-add-api-methods
tswast Nov 2, 2023
39321e4
fix: address comments
ashleyxuu Nov 3, 2023
aebcf11
Remove utils folder and refactor it in core directory
ashleyxuu Nov 3, 2023
72217c2
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 3, 2023
ec526b5
Remove utils folder and refactor it in core directory
ashleyxuu Nov 3, 2023
9edfe31
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 3, 2023
4baa373
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 3, 2023
3a94c23
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 3, 2023
d84c569
fix merge conflicts
ashleyxuu Nov 3, 2023
308c9a7
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 3, 2023
4618107
commit the conflicts
ashleyxuu Nov 13, 2023
a87bcb8
redesign the log adapter
ashleyxuu Nov 14, 2023
cf97f8b
resolve conflicts and merge remote-tracking branch 'origin/main' into…
ashleyxuu Nov 14, 2023
53a99f9
Make the global _api_methods and lock threads
ashleyxuu Nov 14, 2023
3cc3599
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 14, 2023
1c3deb5
Make the global _api_methods and lock threads
ashleyxuu Nov 14, 2023
99f423b
merge conflicts
ashleyxuu Nov 14, 2023
115de27
address comments
ashleyxuu Nov 14, 2023
b0adf27
address comments
ashleyxuu Nov 14, 2023
b4ea9e3
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 14, 2023
df9c9c0
fix error
ashleyxuu Nov 14, 2023
00bb6de
fix None job_config error
ashleyxuu Nov 14, 2023
36fea06
address comments
ashleyxuu Nov 14, 2023
e872d18
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 14, 2023
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
Prev Previous commit
Next Next commit
refactor: ArrayValue is now a tree that defers conversion to ibis (#110)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕
  • Loading branch information
TrevorBergeron authored and ashleyxuu committed Oct 30, 2023
commit a99d62c2e82f6db0786665470531d4b49438aabf
1,221 changes: 216 additions & 1,005 deletions bigframes/core/__init__.py

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions bigframes/core/block_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bigframes.core as core
import bigframes.core.blocks as blocks
import bigframes.core.ordering as ordering
import bigframes.core.window_spec as windows
import bigframes.operations as ops
import bigframes.operations.aggregations as agg_ops

Expand Down Expand Up @@ -68,21 +69,21 @@ def indicate_duplicates(
if keep == "first":
# Count how many copies occur up to current copy of value
# Discard this value if there are copies BEFORE
window_spec = core.WindowSpec(
window_spec = windows.WindowSpec(
grouping_keys=tuple(columns),
following=0,
)
elif keep == "last":
# Count how many copies occur up to current copy of values
# Discard this value if there are copies AFTER
window_spec = core.WindowSpec(
window_spec = windows.WindowSpec(
grouping_keys=tuple(columns),
preceding=0,
)
else: # keep == False
# Count how many copies of the value occur in entire series.
# Discard this value if there are copies ANYWHERE
window_spec = core.WindowSpec(grouping_keys=tuple(columns))
window_spec = windows.WindowSpec(grouping_keys=tuple(columns))
block, dummy = block.create_constant(1)
block, val_count_col_id = block.apply_window_op(
dummy,
Expand Down Expand Up @@ -131,7 +132,7 @@ def value_counts(
)
count_id = agg_ids[0]
if normalize:
unbound_window = core.WindowSpec()
unbound_window = windows.WindowSpec()
block, total_count_id = block.apply_window_op(
count_id, agg_ops.sum_op, unbound_window
)
Expand All @@ -153,7 +154,7 @@ def value_counts(

def pct_change(block: blocks.Block, periods: int = 1) -> blocks.Block:
column_labels = block.column_labels
window_spec = core.WindowSpec(
window_spec = windows.WindowSpec(
preceding=periods if periods > 0 else None,
following=-periods if periods < 0 else None,
)
Expand Down Expand Up @@ -195,7 +196,7 @@ def rank(
ops.isnull_op,
)
nullity_col_ids.append(nullity_col_id)
window = core.WindowSpec(
window = windows.WindowSpec(
# BigQuery has syntax to reorder nulls with "NULLS FIRST/LAST", but that is unavailable through ibis presently, so must order on a separate nullity expression first.
ordering=(
ordering.OrderingColumnReference(
Expand Down Expand Up @@ -229,7 +230,7 @@ def rank(
block, result_id = block.apply_window_op(
rownum_col_ids[i],
agg_op,
window_spec=core.WindowSpec(grouping_keys=[columns[i]]),
window_spec=windows.WindowSpec(grouping_keys=(columns[i],)),
skip_reproject_unsafe=(i < (len(columns) - 1)),
)
post_agg_rownum_col_ids.append(result_id)
Expand Down Expand Up @@ -311,7 +312,7 @@ def nsmallest(
block, counter = block.apply_window_op(
column_ids[0],
agg_ops.rank_op,
window_spec=core.WindowSpec(ordering=order_refs),
window_spec=windows.WindowSpec(ordering=tuple(order_refs)),
)
block, condition = block.apply_unary_op(
counter, ops.partial_right(ops.le_op, n)
Expand Down Expand Up @@ -343,7 +344,7 @@ def nlargest(
block, counter = block.apply_window_op(
column_ids[0],
agg_ops.rank_op,
window_spec=core.WindowSpec(ordering=order_refs),
window_spec=windows.WindowSpec(ordering=tuple(order_refs)),
)
block, condition = block.apply_unary_op(
counter, ops.partial_right(ops.le_op, n)
Expand Down Expand Up @@ -440,14 +441,14 @@ def _mean_delta_to_power(
grouping_column_ids: typing.Sequence[str],
) -> typing.Tuple[blocks.Block, typing.Sequence[str]]:
"""Calculate (x-mean(x))^n. Useful for calculating moment statistics such as skew and kurtosis."""
window = core.WindowSpec(grouping_keys=grouping_column_ids)
window = windows.WindowSpec(grouping_keys=tuple(grouping_column_ids))
block, mean_ids = block.multi_apply_window_op(column_ids, agg_ops.mean_op, window)
delta_ids = []
cube_op = ops.partial_right(ops.pow_op, n_power)
for val_id, mean_val_id in zip(column_ids, mean_ids):
block, delta_id = block.apply_binary_op(val_id, mean_val_id, ops.sub_op)
block, delta_power_id = block.apply_unary_op(delta_id, cube_op)
block = block.drop_columns(delta_id)
block = block.drop_columns([delta_id])
delta_ids.append(delta_power_id)
return block, delta_ids

Expand Down Expand Up @@ -645,7 +646,7 @@ def _idx_extrema(
for idx_col in original_block.index_columns
],
]
window_spec = core.WindowSpec(ordering=order_refs)
window_spec = windows.WindowSpec(ordering=tuple(order_refs))
idx_col = original_block.index_columns[0]
block, result_col = block.apply_window_op(
idx_col, agg_ops.first_op, window_spec
Expand Down
34 changes: 18 additions & 16 deletions bigframes/core/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import bigframes.core as core
import bigframes.core.guid as guid
import bigframes.core.indexes as indexes
import bigframes.core.joins as joins
import bigframes.core.joins.name_resolution as join_names
import bigframes.core.ordering as ordering
import bigframes.core.utils
Expand Down Expand Up @@ -378,7 +377,7 @@ def _to_dataframe(self, result) -> pd.DataFrame:
"""Convert BigQuery data to pandas DataFrame with specific dtypes."""
dtypes = dict(zip(self.index_columns, self.index_dtypes))
dtypes.update(zip(self.value_columns, self.dtypes))
return self._expr._session._rows_to_dataframe(result, dtypes)
return self._expr.session._rows_to_dataframe(result, dtypes)

def to_pandas(
self,
Expand Down Expand Up @@ -422,7 +421,7 @@ def to_pandas_batches(self):
dtypes.update(zip(self.value_columns, self.dtypes))
results_iterator, _ = self._expr.start_query()
for arrow_table in results_iterator.to_arrow_iterable(
bqstorage_client=self._expr._session.bqstoragereadclient
bqstorage_client=self._expr.session.bqstoragereadclient
):
df = bigframes.session._io.pandas.arrow_to_pandas(arrow_table, dtypes)
self._copy_index_to_pandas(df)
Expand Down Expand Up @@ -454,7 +453,9 @@ def _compute_and_count(

results_iterator, query_job = expr.start_query(max_results=max_results)

table_size = expr._get_table_size(query_job.destination) / _BYTES_TO_MEGABYTES
table_size = (
expr.session._get_table_size(query_job.destination) / _BYTES_TO_MEGABYTES
)
fraction = (
max_download_size / table_size
if (max_download_size is not None) and (table_size != 0)
Expand Down Expand Up @@ -819,7 +820,9 @@ def aggregate_all_and_stack(
axis: int | str = 0,
value_col_id: str = "values",
dropna: bool = True,
dtype=pd.Float64Dtype(),
dtype: typing.Union[
bigframes.dtypes.Dtype, typing.Tuple[bigframes.dtypes.Dtype, ...]
] = pd.Float64Dtype(),
) -> Block:
axis_n = utils.get_axis_number(axis)
if axis_n == 0:
Expand All @@ -829,7 +832,7 @@ def aggregate_all_and_stack(
result_expr = self.expr.aggregate(aggregations, dropna=dropna).unpivot(
row_labels=self.column_labels.to_list(),
index_col_ids=["index"],
unpivot_columns=[(value_col_id, self.value_columns)],
unpivot_columns=tuple([(value_col_id, tuple(self.value_columns))]),
dtype=dtype,
)
return Block(result_expr, index_columns=["index"], column_labels=[None])
Expand All @@ -841,7 +844,7 @@ def aggregate_all_and_stack(
stacked_expr = expr_with_offsets.unpivot(
row_labels=self.column_labels.to_list(),
index_col_ids=[guid.generate_guid()],
unpivot_columns=[(value_col_id, self.value_columns)],
unpivot_columns=[(value_col_id, tuple(self.value_columns))],
passthrough_columns=[*self.index_columns, offset_col],
dtype=dtype,
)
Expand Down Expand Up @@ -1029,13 +1032,13 @@ def summarize(
for col_id in column_ids
]
columns = [
(col_id, [f"{col_id}-{stat.name}" for stat in stats])
(col_id, tuple(f"{col_id}-{stat.name}" for stat in stats))
for col_id in column_ids
]
expr = self.expr.aggregate(aggregations).unpivot(
labels,
unpivot_columns=columns,
index_col_ids=[label_col_id],
unpivot_columns=tuple(columns),
index_col_ids=tuple([label_col_id]),
)
labels = self._get_labels_for_columns(column_ids)
return Block(expr, column_labels=labels, index_columns=[label_col_id])
Expand Down Expand Up @@ -1342,7 +1345,7 @@ def stack(self, how="left", levels: int = 1):
passthrough_columns=self.index_columns,
unpivot_columns=unpivot_columns,
index_col_ids=added_index_columns,
dtype=dtypes,
dtype=tuple(dtypes),
how=how,
)
new_index_level_names = self.column_labels.names[-levels:]
Expand Down Expand Up @@ -1382,7 +1385,7 @@ def _create_stack_column(
dtype = self._column_type(input_id)
input_columns.append(input_id)
# Input column i is the first one that
return input_columns, dtype or pd.Float64Dtype()
return tuple(input_columns), dtype or pd.Float64Dtype()

def _column_type(self, col_id: str) -> bigframes.dtypes.Dtype:
col_offset = self.value_columns.index(col_id)
Expand Down Expand Up @@ -1497,8 +1500,7 @@ def merge(
sort: bool,
suffixes: tuple[str, str] = ("_x", "_y"),
) -> Block:
joined_expr = joins.join_by_column(
self.expr,
joined_expr = self.expr.join(
left_join_ids,
other.expr,
right_join_ids,
Expand Down Expand Up @@ -1708,7 +1710,7 @@ def _is_monotonic(
return result


def block_from_local(data, session=None) -> Block:
def block_from_local(data) -> Block:
pd_data = pd.DataFrame(data)
columns = pd_data.columns

Expand All @@ -1730,7 +1732,7 @@ def block_from_local(data, session=None) -> Block:
)
index_ids = pd_data.columns[: len(index_labels)]

keys_expr = core.ArrayValue.mem_expr_from_pandas(pd_data, session)
keys_expr = core.ArrayValue.from_pandas(pd_data)
return Block(
keys_expr,
column_labels=columns,
Expand Down
21 changes: 21 additions & 0 deletions bigframes/core/compile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from bigframes.core.compile.compiled import CompiledArrayValue
from bigframes.core.compile.compiler import compile_node

__all__ = [
"compile_node",
"CompiledArrayValue",
]
Loading