Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 483b301

Browse files
Merge remote-tracking branch 'github/main' into prerelease_and_pandas_3
2 parents c7439e4 + a2f2b65 commit 483b301

12 files changed

Lines changed: 571 additions & 686 deletions

File tree

bigframes/bigquery/_operations/ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def _convert_series(
10181018

10191019
def _resolve_connection_id(series: series.Series, connection_id: str | None):
10201020
return clients.get_canonical_bq_connection_id(
1021-
connection_id or series._session._bq_connection,
1021+
connection_id or series._session.bq_connection,
10221022
series._session._project,
10231023
series._session._location,
10241024
)

bigframes/core/array_value.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ def filter_by_id(self, predicate_id: str, keep_null: bool = False) -> ArrayValue
204204
return self.filter(predicate)
205205

206206
def filter(self, predicate: ex.Expression):
207-
return ArrayValue(nodes.FilterNode(child=self.node, predicate=predicate))
207+
if predicate.is_scalar_expr:
208+
return ArrayValue(nodes.FilterNode(child=self.node, predicate=predicate))
209+
else:
210+
arr, filter_ids = self.compute_general_expression([predicate])
211+
arr = arr.filter_by_id(filter_ids[0])
212+
return arr.drop_columns(filter_ids)
208213

209214
def order_by(
210215
self, by: Sequence[OrderingExpression], is_total_order: bool = False

bigframes/core/indexers.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import pandas as pd
2424

2525
import bigframes.core.blocks
26+
import bigframes.core.col
2627
import bigframes.core.expression as ex
2728
import bigframes.core.guid as guid
2829
import bigframes.core.indexes as indexes
@@ -36,7 +37,11 @@
3637

3738
if typing.TYPE_CHECKING:
3839
LocSingleKey = Union[
39-
bigframes.series.Series, indexes.Index, slice, bigframes.core.scalar.Scalar
40+
bigframes.series.Series,
41+
indexes.Index,
42+
slice,
43+
bigframes.core.scalar.Scalar,
44+
bigframes.core.col.Expression,
4045
]
4146

4247

@@ -309,6 +314,15 @@ def _loc_getitem_series_or_dataframe(
309314
raise NotImplementedError(
310315
f"loc does not yet support indexing with a slice. {constants.FEEDBACK_LINK}"
311316
)
317+
if isinstance(key, bigframes.core.col.Expression):
318+
label_to_col_ref = {
319+
label: ex.deref(id)
320+
for id, label in series_or_dataframe._block.col_id_to_label.items()
321+
}
322+
resolved_expr = key._value.bind_variables(label_to_col_ref)
323+
result = series_or_dataframe.copy()
324+
result._set_block(series_or_dataframe._block.filter(resolved_expr))
325+
return result
312326
if callable(key):
313327
raise NotImplementedError(
314328
f"loc does not yet support indexing with a callable. {constants.FEEDBACK_LINK}"

bigframes/dataframe.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,18 @@ def __getitem__(
623623
): # No return type annotations (like pandas) as type cannot always be determined statically
624624
# NOTE: This implements the operations described in
625625
# https://pandas.pydata.org/docs/getting_started/intro_tutorials/03_subset_data.html
626+
import bigframes.core.col
627+
import bigframes.pandas
626628

627-
if isinstance(key, bigframes.series.Series):
629+
if isinstance(key, bigframes.pandas.Series):
628630
return self._getitem_bool_series(key)
629631

630632
if isinstance(key, slice):
631633
return self.iloc[key]
632634

635+
if isinstance(key, bigframes.core.col.Expression):
636+
return self.loc[key]
637+
633638
# TODO(tswast): Fix this pylance warning: Class overlaps "Hashable"
634639
# unsafely and could produce a match at runtime
635640
if isinstance(key, blocks.Label):

bigframes/functions/_function_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _resolve_bigquery_connection_id(
162162
) -> str:
163163
"""Resolves BigQuery connection id."""
164164
if not bigquery_connection:
165-
bigquery_connection = session._bq_connection # type: ignore
165+
bigquery_connection = session.bq_connection # type: ignore
166166

167167
bigquery_connection = clients.get_canonical_bq_connection_id(
168168
bigquery_connection,

bigframes/ml/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ class Claude3TextGenerator(base.RetriableRemotePredictor):
877877
The model for natural language tasks. Possible values are "claude-3-sonnet", "claude-3-haiku", "claude-3-5-sonnet" and "claude-3-opus".
878878
"claude-3-sonnet" (deprecated) is Anthropic's dependable combination of skills and speed. It is engineered to be dependable for scaled AI deployments across a variety of use cases.
879879
"claude-3-haiku" is Anthropic's fastest, most compact vision and text model for near-instant responses to simple queries, meant for seamless AI experiences mimicking human interactions.
880-
"claude-3-5-sonnet" is Anthropic's most powerful AI model and maintains the speed and cost of Claude 3 Sonnet, which is a mid-tier model.
880+
"claude-3-5-sonnet" (deprecated) is Anthropic's most powerful AI model and maintains the speed and cost of Claude 3 Sonnet, which is a mid-tier model.
881881
"claude-3-opus" (deprecated) is Anthropic's second-most powerful AI model, with strong performance on highly complex tasks.
882882
https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#available-claude-models
883883
If no setting is provided, "claude-3-sonnet" will be used by default

bigframes/operations/blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _resolve_connection(self, connection: Optional[str] = None) -> str:
311311
Raises:
312312
ValueError: If the connection cannot be resolved to a valid string.
313313
"""
314-
connection = connection or self._data._block.session._bq_connection
314+
connection = connection or self._data._block.session.bq_connection
315315
return clients.get_canonical_bq_connection_id(
316316
connection,
317317
default_project=self._data._block.session._project,

bigframes/session/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ def _allows_ambiguity(self) -> bool:
374374
def _anonymous_dataset(self):
375375
return self._anon_dataset_manager.dataset
376376

377+
@property
378+
def bq_connection(self) -> str:
379+
msg = bfe.format_message(
380+
f"""You are using the BigFrames session default connection: {self._bq_connection},
381+
which can be different from the BigQuery project default connection.
382+
This default connection may change in the future."""
383+
)
384+
warnings.warn(msg, category=FutureWarning)
385+
return self._bq_connection
386+
377387
def __hash__(self):
378388
# Stable hash needed to use in expression tree
379389
return hash(str(self._session_id))
@@ -2253,7 +2263,7 @@ def _create_bq_connection(
22532263
) -> str:
22542264
"""Create the connection with the session settings and try to attach iam role to the connection SA.
22552265
If any of project, location or connection isn't specified, use the session defaults. Returns fully-qualified connection name."""
2256-
connection = self._bq_connection if not connection else connection
2266+
connection = self.bq_connection if not connection else connection
22572267
connection = bigframes.clients.get_canonical_bq_connection_id(
22582268
connection_id=connection,
22592269
default_project=self._project,

0 commit comments

Comments
 (0)