Skip to content

Commit 78bfccf

Browse files
committed
fix unit tests
1 parent c85d47f commit 78bfccf

File tree

11 files changed

+82
-33
lines changed

11 files changed

+82
-33
lines changed

bigframes/bigquery/_operations/ai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def generate_int(
201201
202202
>>> import bigframes.pandas as bpd
203203
>>> import bigframes.bigquery as bbq
204-
>>> animal = bpd.Series(["Kangaroo", "Rabbit", "Spider"])
204+
>>> animal = bpd.Series(["Kangaroo", "Rabbit", "Spider"])
205205
>>> bbq.ai.generate_int(("How many legs does a ", animal, " have?"))
206206
0 {'result': 2, 'full_response': '{"candidates":...
207207
1 {'result': 4, 'full_response': '{"candidates":...
@@ -275,7 +275,7 @@ def generate_double(
275275
276276
>>> import bigframes.pandas as bpd
277277
>>> import bigframes.bigquery as bbq
278-
>>> animal = bpd.Series(["Kangaroo", "Rabbit", "Spider"])
278+
>>> animal = bpd.Series(["Kangaroo", "Rabbit", "Spider"])
279279
>>> bbq.ai.generate_double(("How many legs does a ", animal, " have?"))
280280
0 {'result': 2.0, 'full_response': '{"candidates...
281281
1 {'result': 4.0, 'full_response': '{"candidates...
@@ -346,7 +346,7 @@ def if_(
346346
**Examples:**
347347
>>> import bigframes.pandas as bpd
348348
>>> import bigframes.bigquery as bbq
349-
>>> us_state = bpd.Series(["Massachusetts", "Illinois", "Hawaii"])
349+
>>> us_state = bpd.Series(["Massachusetts", "Illinois", "Hawaii"])
350350
>>> bbq.ai.if_((us_state, " has a city called Springfield"))
351351
0 True
352352
1 True
@@ -395,7 +395,7 @@ def classify(
395395
396396
>>> import bigframes.pandas as bpd
397397
>>> import bigframes.bigquery as bbq
398-
>>> df = bpd.DataFrame({'creature': ['Cat', 'Salmon']})
398+
>>> df = bpd.DataFrame({'creature': ['Cat', 'Salmon']})
399399
>>> df['type'] = bbq.ai.classify(df['creature'], ['Mammal', 'Fish'])
400400
>>> df
401401
creature type
@@ -445,7 +445,7 @@ def score(
445445
446446
>>> import bigframes.pandas as bpd
447447
>>> import bigframes.bigquery as bbq
448-
>>> animal = bpd.Series(["Tiger", "Rabbit", "Blue Whale"])
448+
>>> animal = bpd.Series(["Tiger", "Rabbit", "Blue Whale"])
449449
>>> bbq.ai.score(("Rank the relative weights of ", animal, " on the scale from 1 to 3")) # doctest: +SKIP
450450
0 2.0
451451
1 1.0

bigframes/core/tools/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def to_datetime(
4242
utc: bool = False,
4343
format: Optional[str] = None,
4444
unit: Optional[str] = None,
45-
session: Optional[bigframes.session.Session],
45+
session: Optional[bigframes.session.Session] = None,
4646
) -> Union[pd.Timestamp, datetime, bigframes.series.Series]:
4747
if isinstance(arg, (int, float, str, datetime, date)):
4848
return pd.to_datetime(

bigframes/operations/ai.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def map(
114114
**Examples:**
115115
116116
>>> import bigframes.pandas as bpd
117-
>>> bpd.options.experiments.ai_operators = True
117+
>>> bpd.options.experiments.ai_operators = True
118118
>>> bpd.options.compute.ai_ops_confirmation_threshold = 25
119119
120120
>>> import bigframes.ml.llm as llm
@@ -132,7 +132,7 @@ def map(
132132
133133
134134
>>> import bigframes.pandas as bpd
135-
>>> bpd.options.experiments.ai_operators = True
135+
>>> bpd.options.experiments.ai_operators = True
136136
>>> bpd.options.compute.ai_ops_confirmation_threshold = 25
137137
138138
>>> import bigframes.ml.llm as llm
@@ -263,7 +263,7 @@ def classify(
263263
**Examples:**
264264
265265
>>> import bigframes.pandas as bpd
266-
>>> bpd.options.experiments.ai_operators = True
266+
>>> bpd.options.experiments.ai_operators = True
267267
>>> bpd.options.compute.ai_ops_confirmation_threshold = 25
268268
269269
>>> import bigframes.ml.llm as llm
@@ -352,7 +352,7 @@ def join(
352352
**Examples:**
353353
354354
>>> import bigframes.pandas as bpd
355-
>>> bpd.options.experiments.ai_operators = True
355+
>>> bpd.options.experiments.ai_operators = True
356356
>>> bpd.options.compute.ai_ops_confirmation_threshold = 25
357357
358358
>>> import bigframes.ml.llm as llm
@@ -602,7 +602,7 @@ def sim_join(
602602
** Examples: **
603603
604604
>>> import bigframes.pandas as bpd
605-
>>> bpd.options.experiments.ai_operators = True
605+
>>> bpd.options.experiments.ai_operators = True
606606
>>> bpd.options.compute.ai_ops_confirmation_threshold = 25
607607
608608
>>> import bigframes.ml.llm as llm

bigframes/operations/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(
135135
# explicitly chose even if it is None. This is important for the
136136
# polars backend where the implicit column labels are integers.
137137
if not isinstance(data, blocks.Block):
138-
block = block.with_column_labels([name])
138+
block = block.with_column_labels([name or getattr(data, "name", None)])
139139

140140
self._block: blocks.Block = block
141141

bigframes/operations/semantics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def cluster_by(
246246
**Examples:**
247247
248248
>>> import bigframes.pandas as bpd
249-
>>> bpd.options.experiments.semantic_operators = True
249+
>>> bpd.options.experiments.semantic_operators = True
250250
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
251251
252252
>>> import bigframes.ml.llm as llm
@@ -319,7 +319,7 @@ def filter(self, instruction: str, model, ground_with_google_search: bool = Fals
319319
**Examples:**
320320
321321
>>> import bigframes.pandas as bpd
322-
>>> bpd.options.experiments.semantic_operators = True
322+
>>> bpd.options.experiments.semantic_operators = True
323323
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
324324
325325
>>> import bigframes.ml.llm as llm
@@ -432,7 +432,7 @@ def map(
432432
**Examples:**
433433
434434
>>> import bigframes.pandas as bpd
435-
>>> bpd.options.experiments.semantic_operators = True
435+
>>> bpd.options.experiments.semantic_operators = True
436436
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
437437
438438
>>> import bigframes.ml.llm as llm
@@ -554,7 +554,7 @@ def join(
554554
**Examples:**
555555
556556
>>> import bigframes.pandas as bpd
557-
>>> bpd.options.experiments.semantic_operators = True
557+
>>> bpd.options.experiments.semantic_operators = True
558558
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
559559
560560
>>> import bigframes.ml.llm as llm
@@ -794,7 +794,7 @@ def top_k(
794794
**Examples:**
795795
796796
>>> import bigframes.pandas as bpd
797-
>>> bpd.options.experiments.semantic_operators = True
797+
>>> bpd.options.experiments.semantic_operators = True
798798
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
799799
800800
>>> import bigframes.ml.llm as llm
@@ -994,7 +994,7 @@ def sim_join(
994994
** Examples: **
995995
996996
>>> import bigframes.pandas as bpd
997-
>>> bpd.options.experiments.semantic_operators = True
997+
>>> bpd.options.experiments.semantic_operators = True
998998
>>> bpd.options.compute.semantic_ops_confirmation_threshold = 25
999999
10001000
>>> import bigframes.ml.llm as llm

bigframes/pandas/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ def to_datetime(
226226
format=format,
227227
unit=unit,
228228
)
229-
return bigframes.core.tools.to_datetime()
230229

231230

232231
to_datetime.__doc__ = vendored_pandas_datetimes.to_datetime.__doc__

bigframes/session/__init__.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,6 +2291,12 @@ def read_gbq_object_table(
22912291
# interchangeably.
22922292
# =========================================================================
22932293
def cut(self, *args, **kwargs) -> bigframes.series.Series:
2294+
"""Cuts a BigQuery DataFrames object.
2295+
2296+
Included for compatibility between bpd and Session.
2297+
2298+
See :func:`bigframes.pandas.cut` for full documentation.
2299+
"""
22942300
import bigframes.core.reshape.tile
22952301

22962302
return bigframes.core.reshape.tile.cut(
@@ -2299,7 +2305,7 @@ def cut(self, *args, **kwargs) -> bigframes.series.Series:
22992305
**kwargs,
23002306
)
23012307

2302-
def DataFrame(self, *args, **kwargs) -> bigframes.dataframe.DataFrame:
2308+
def DataFrame(self, *args, **kwargs):
23032309
"""Constructs a DataFrame.
23042310
23052311
Included for compatibility between bpd and Session.
@@ -2310,7 +2316,7 @@ def DataFrame(self, *args, **kwargs) -> bigframes.dataframe.DataFrame:
23102316

23112317
return bigframes.dataframe.DataFrame(*args, session=self, **kwargs)
23122318

2313-
def MultiIndex(self, *args, **kwargs) -> bigframes.core.indexes.MultiIndex:
2319+
def MultiIndex(self, *args, **kwargs):
23142320
"""Constructs a MultiIndex.
23152321
23162322
Included for compatibility between bpd and Session.
@@ -2325,7 +2331,7 @@ def MultiIndex(self, *args, **kwargs) -> bigframes.core.indexes.MultiIndex:
23252331
MultiIndex.from_frame = bigframes.core.indexes.MultiIndex.from_frame # type: ignore
23262332
MultiIndex.from_arrays = bigframes.core.indexes.MultiIndex.from_arrays # type: ignore
23272333

2328-
def Index(self, *args, **kwargs) -> bigframes.core.indexes.Index:
2334+
def Index(self, *args, **kwargs):
23292335
"""Constructs a Index.
23302336
23312337
Included for compatibility between bpd and Session.
@@ -2336,7 +2342,7 @@ def Index(self, *args, **kwargs) -> bigframes.core.indexes.Index:
23362342

23372343
return bigframes.core.indexes.Index(*args, session=self, **kwargs)
23382344

2339-
def Series(self, *args, **kwargs) -> bigframes.series.Series:
2345+
def Series(self, *args, **kwargs):
23402346
"""Constructs a Series.
23412347
23422348
Included for compatibility between bpd and Session.
@@ -2350,6 +2356,12 @@ def Series(self, *args, **kwargs) -> bigframes.series.Series:
23502356
def to_datetime(
23512357
self, *args, **kwargs
23522358
) -> Union[pandas.Timestamp, datetime.datetime, bigframes.series.Series]:
2359+
"""Converts a BigQuery DataFrames object to datetime dtype.
2360+
2361+
Included for compatibility between bpd and Session.
2362+
2363+
See :func:`bigframes.pandas.to_datetime` for full documentation.
2364+
"""
23532365
import bigframes.core.tools
23542366

23552367
return bigframes.core.tools.to_datetime(
@@ -2359,6 +2371,12 @@ def to_datetime(
23592371
)
23602372

23612373
def to_timedelta(self, *args, **kwargs):
2374+
"""Converts a BigQuery DataFrames object to timedelta/duration dtype.
2375+
2376+
Included for compatibility between bpd and Session.
2377+
2378+
See :func:`bigframes.pandas.to_timedelta` for full documentation.
2379+
"""
23622380
import bigframes.pandas.core.tools.timedeltas
23632381

23642382
return bigframes.pandas.core.tools.timedeltas.to_timedelta(

scripts/publish_api_coverage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pandas.core.indexes.accessors
2626
import pandas.core.strings.accessor
2727
import pandas.core.window.rolling
28+
import sklearn # noqa
2829

2930
import bigframes
3031
import bigframes.core.groupby

tests/unit/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2025 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+
import pytest
16+
17+
18+
@pytest.fixture(scope="session")
19+
def polars_session():
20+
pytest.importorskip("polars")
21+
22+
from bigframes.testing import polars_session
23+
24+
return polars_session.TestSession()

tests/unit/test_pandas.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ def test_method_matches_session(method_name: str):
6464
pandas_method = getattr(bigframes.pandas, method_name)
6565
pandas_doc = inspect.getdoc(pandas_method)
6666
assert pandas_doc is not None, "docstrings are required"
67-
assert re.sub(leading_whitespace, "", pandas_doc) == re.sub(
68-
leading_whitespace, "", session_doc
67+
68+
pandas_doc_stripped = re.sub(leading_whitespace, "", pandas_doc)
69+
session_doc_stripped = re.sub(leading_whitespace, "", session_doc)
70+
assert (
71+
pandas_doc_stripped == session_doc_stripped
72+
or ":`bigframes.pandas" in session_doc_stripped
6973
)
7074

7175
# Add `eval_str = True` so that deferred annotations are turned into their
@@ -75,18 +79,20 @@ def test_method_matches_session(method_name: str):
7579
eval_str=True,
7680
globals={**vars(bigframes.session), **{"dataframe": bigframes.dataframe}},
7781
)
78-
pandas_signature = inspect.signature(pandas_method, eval_str=True)
79-
assert [
80-
# Kind includes position, which will be an offset.
81-
parameter.replace(kind=inspect.Parameter.POSITIONAL_ONLY)
82-
for parameter in pandas_signature.parameters.values()
83-
] == [
82+
session_args = [
8483
# Kind includes position, which will be an offset.
8584
parameter.replace(kind=inspect.Parameter.POSITIONAL_ONLY)
8685
for parameter in session_signature.parameters.values()
8786
# Don't include the first parameter, which is `self: Session`
88-
][
89-
1:
87+
][1:]
88+
pandas_signature = inspect.signature(pandas_method, eval_str=True)
89+
pandas_args = [
90+
# Kind includes position, which will be an offset.
91+
parameter.replace(kind=inspect.Parameter.POSITIONAL_ONLY)
92+
for parameter in pandas_signature.parameters.values()
93+
]
94+
assert session_args == pandas_args or ["args", "kwargs"] == [
95+
parameter.name for parameter in session_args
9096
]
9197
assert pandas_signature.return_annotation == session_signature.return_annotation
9298

0 commit comments

Comments
 (0)