Skip to content

Commit a4b0c40

Browse files
Merge branch 'main' into neo_bqml
2 parents ca61276 + b9e6150 commit a4b0c40

File tree

8 files changed

+21
-8
lines changed

8 files changed

+21
-8
lines changed

bigframes/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@
9999

100100
# BigQuery default is 10000, leave 100 for overhead
101101
MAX_COLUMNS = 9900
102+
103+
SUGGEST_PEEK_PREVIEW = "Use .peek(n) to preview n arbitrary rows."

bigframes/core/groupby/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __getitem__(
109109
dropna=self._dropna,
110110
)
111111

112+
@validations.requires_strict_ordering()
112113
def head(self, n: int = 5) -> df.DataFrame:
113114
block = self._block
114115
if self._dropna:
@@ -531,6 +532,7 @@ def __init__(
531532
def _session(self) -> core.Session:
532533
return self._block.session
533534

535+
@validations.requires_strict_ordering()
534536
def head(self, n: int = 5) -> series.Series:
535537
block = self._block
536538
if self._dropna:

bigframes/core/validations.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from __future__ import annotations
1818

1919
import functools
20-
from typing import Protocol, TYPE_CHECKING
20+
from typing import Optional, Protocol, TYPE_CHECKING
2121

2222
import bigframes.constants
2323
import bigframes.exceptions
@@ -32,20 +32,23 @@ def _session(self) -> Session:
3232
...
3333

3434

35-
def requires_strict_ordering():
35+
def requires_strict_ordering(suggestion: Optional[str] = None):
3636
def decorator(meth):
3737
@functools.wraps(meth)
3838
def guarded_meth(object: HasSession, *args, **kwargs):
39-
enforce_ordered(object, meth.__name__)
39+
enforce_ordered(object, meth.__name__, suggestion)
4040
return meth(object, *args, **kwargs)
4141

4242
return guarded_meth
4343

4444
return decorator
4545

4646

47-
def enforce_ordered(object: HasSession, opname: str) -> None:
47+
def enforce_ordered(
48+
object: HasSession, opname: str, suggestion: Optional[str] = None
49+
) -> None:
4850
if not object._session._strictly_ordered:
51+
suggestion_substr = suggestion + " " if suggestion else ""
4952
raise bigframes.exceptions.OrderRequiredError(
50-
f"Op {opname} not supported when strict ordering is disabled. {bigframes.constants.FEEDBACK_LINK}"
53+
f"Op {opname} not supported when strict ordering is disabled. {suggestion_substr}{bigframes.constants.FEEDBACK_LINK}"
5154
)

bigframes/dataframe.py

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
import bigframes
5151
import bigframes._config.display_options as display_options
52+
import bigframes.constants
5253
import bigframes.constants as constants
5354
import bigframes.core
5455
from bigframes.core import log_adapter
@@ -1293,6 +1294,7 @@ def _compute_dry_run(self) -> bigquery.QueryJob:
12931294
def copy(self) -> DataFrame:
12941295
return DataFrame(self._block)
12951296

1297+
@validations.requires_strict_ordering(bigframes.constants.SUGGEST_PEEK_PREVIEW)
12961298
def head(self, n: int = 5) -> DataFrame:
12971299
return typing.cast(DataFrame, self.iloc[:n])
12981300

bigframes/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def dropna(
633633
result = result.reset_index()
634634
return Series(result)
635635

636-
@validations.requires_strict_ordering()
636+
@validations.requires_strict_ordering(bigframes.constants.SUGGEST_PEEK_PREVIEW)
637637
def head(self, n: int = 5) -> Series:
638638
return typing.cast(Series, self.iloc[0:n])
639639

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# samples/snippets should be runnable with no "extras"
22
google-cloud-testutils==1.4.0
3-
pytest==8.2.0
3+
pytest==8.2.1

samples/snippets/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# samples/snippets should be runnable with no "extras"
2-
bigframes==1.6.0
2+
bigframes==1.7.0

tests/system/small/test_unordered.py

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ def test_unordered_drop_duplicates(unordered_session, keep):
131131
lambda x: x.a.iloc[1::2],
132132
id="series_iloc",
133133
),
134+
pytest.param(
135+
lambda x: x.head(3),
136+
id="head",
137+
),
134138
],
135139
)
136140
def test_unordered_mode_blocks_windowing(unordered_session, function):

0 commit comments

Comments
 (0)