Skip to content

Commit ee74e31

Browse files
authored
feat(bigframes): add AI TVFs to the pandas bq accessor (googleapis#17402)
Also updated the tests to fully utilize the mocking framework. internal issue: b/517233441
1 parent 3a67b7f commit ee74e31

12 files changed

Lines changed: 812 additions & 273 deletions

File tree

packages/bigframes/bigframes/extensions/bigframes/series_accessor.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,68 @@
2020

2121
from typing import Optional, TypeVar, cast
2222

23-
import bigframes.extensions.core.series_accessor as core_accessor
24-
import bigframes.series
25-
import bigframes.session
23+
from bigframes import dataframe, series, session
2624
from bigframes.core.logging import log_adapter
25+
from bigframes.extensions.core import series_accessor as core_accessor
2726

28-
S = TypeVar("S", bound="bigframes.series.Series")
27+
T = TypeVar("T", bound="dataframe.DataFrame")
28+
S = TypeVar("S", bound="series.Series")
2929

3030

3131
@log_adapter.class_logger
32-
class BigframesBigQuerySeriesAccessor(core_accessor.BigQuerySeriesAccessor[S]):
32+
class BigframesBigQuerySeriesAccessor(core_accessor.BigQuerySeriesAccessor[T, S]):
3333
def __init__(self, bf_obj: S):
3434
super().__init__(bf_obj)
3535

3636
def _bf_from_series(
37-
self, session: Optional[bigframes.session.Session] = None
38-
) -> bigframes.series.Series:
37+
self, session: Optional[session.Session] = None
38+
) -> series.Series:
3939
return self._obj
4040

41-
def _to_series(self, bf_series: bigframes.series.Series) -> S:
41+
def _to_dataframe(self, bf_df: dataframe.DataFrame) -> T:
42+
return cast(T, bf_df)
43+
44+
def _to_series(self, bf_series: series.Series) -> S:
4245
return cast(S, bf_series)
4346

4447
@property
45-
def aead(self) -> BigframesAeadSeriesAccessor[S]:
48+
def ai(self) -> BigframesAiSeriesAccessor[T, S]:
49+
return BigframesAiSeriesAccessor(self._obj)
50+
51+
@property
52+
def aead(self) -> BigframesAeadSeriesAccessor[T, S]:
4653
return BigframesAeadSeriesAccessor(self._obj)
4754

4855

4956
@log_adapter.class_logger
50-
class BigframesAeadSeriesAccessor(core_accessor.AeadSeriesAccessor[S]):
57+
class BigframesAiSeriesAccessor(core_accessor.AiSeriesAccessor[T, S]):
5158
def __init__(self, bf_obj: S):
5259
super().__init__(bf_obj)
5360

5461
def _bf_from_series(
55-
self, session: Optional[bigframes.session.Session] = None
56-
) -> bigframes.series.Series:
62+
self, session: Optional[session.Session] = None
63+
) -> series.Series:
5764
return self._obj
5865

59-
def _to_series(self, bf_series: bigframes.series.Series) -> S:
66+
def _to_dataframe(self, bf_df: dataframe.DataFrame) -> T:
67+
return cast(T, bf_df)
68+
69+
def _to_series(self, bf_series: series.Series) -> S:
70+
return cast(S, bf_series)
71+
72+
73+
@log_adapter.class_logger
74+
class BigframesAeadSeriesAccessor(core_accessor.AeadSeriesAccessor[T, S]):
75+
def __init__(self, bf_obj: S):
76+
super().__init__(bf_obj)
77+
78+
def _bf_from_series(
79+
self, session: Optional[session.Session] = None
80+
) -> series.Series:
81+
return self._obj
82+
83+
def _to_dataframe(self, bf_df: dataframe.DataFrame) -> T:
84+
return cast(T, bf_df)
85+
86+
def _to_series(self, bf_series: series.Series) -> S:
6087
return cast(S, bf_series)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# DO NOT MODIFY THIS FILE DIRECTLY.
16+
# This file was generated by the script: scripts/generate_bigframes_bigquery.py
17+
#
18+
19+
from __future__ import annotations
20+
21+
import abc
22+
from typing import (
23+
Generic,
24+
Optional,
25+
TypeVar,
26+
)
27+
28+
from bigframes import dataframe, series, session
29+
30+
T = TypeVar("T")
31+
S = TypeVar("S")
32+
33+
34+
class AbstractBigQuerySeriesAccessor(abc.ABC, Generic[T, S]):
35+
def __init__(self, obj: S):
36+
self._obj = obj
37+
38+
@abc.abstractmethod
39+
def _bf_from_series(
40+
self, session: Optional[session.Session] = None
41+
) -> series.Series:
42+
"""Convert the accessor's object to a BigFrames Series."""
43+
44+
@abc.abstractmethod
45+
def _to_dataframe(self, bf_df: dataframe.DataFrame) -> T:
46+
"""Convert a BigFrames DataFrame to the accessor's object type."""
47+
48+
@abc.abstractmethod
49+
def _to_series(self, bf_series: series.Series) -> S:
50+
"""Convert a BigFrames Series to the accessor's object type."""

0 commit comments

Comments
 (0)