Skip to content

Commit d2165d4

Browse files
fix errors
1 parent 069abf4 commit d2165d4

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

bigframes/core/indexes/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,11 @@ def to_list(self, *, allow_large_results: Optional[bool] = None) -> list:
778778
def __len__(self):
779779
return self.shape[0]
780780

781+
def __bool__(self):
782+
raise ValueError(
783+
"Cannot convert Index into bool. Consider using .empty(), .item(), .any(), or .all() methods."
784+
)
785+
781786
def item(self):
782787
# Docstring is in third_party/bigframes_vendored/pandas/core/indexes/base.py
783788
return self.to_series().peek(2).item()

bigframes/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ def __len__(self):
388388
rows, _ = self.shape
389389
return rows
390390

391+
def __bool__(self):
392+
raise ValueError(
393+
"Cannot convert dataframe into bool. Consider using .empty(), .any(), or .all() methods."
394+
)
395+
391396
def __iter__(self):
392397
return iter(self.columns)
393398

bigframes/series.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ def _set_internal_query_job(self, query_job: Optional[bigquery.QueryJob]):
359359
def __len__(self):
360360
return self.shape[0]
361361

362+
def __bool__(self):
363+
raise ValueError(
364+
"Cannot convert Series into bool. Consider using .empty(), .item(), .any(), or .all() methods."
365+
)
366+
362367
def __iter__(self) -> typing.Iterator:
363368
return itertools.chain.from_iterable(
364369
map(lambda x: x.squeeze(axis=1), self._block.to_pandas_batches())

third_party/bigframes_vendored/pandas/core/computation/align.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
from functools import partial, wraps
8-
from typing import Callable, TYPE_CHECKING
8+
from typing import Callable, TYPE_CHECKING, Union
99
import warnings
1010

1111
import bigframes_vendored.pandas.core.common as com
@@ -17,15 +17,18 @@
1717
if TYPE_CHECKING:
1818
from collections.abc import Sequence
1919

20-
from bigframes_vendored.pandas.core.generic import NDFrame
2120
from bigframes_vendored.pandas.core.indexes.base import Index
2221
from pandas._typing import F
2322

23+
from bigframes.pandas import DataFrame, Series
24+
25+
FrameT = Union[Series, DataFrame]
26+
2427

2528
def _align_core_single_unary_op(
2629
term,
27-
) -> tuple[partial | type[NDFrame], dict[str, Index] | None]:
28-
typ: partial | type[NDFrame]
30+
) -> tuple[partial | FrameT, dict[str, Index] | None]:
31+
typ: partial | FrameT
2932
axes: dict[str, Index] | None = None
3033

3134
if isinstance(term.value, np.ndarray):
@@ -38,9 +41,7 @@ def _align_core_single_unary_op(
3841
return typ, axes
3942

4043

41-
def _zip_axes_from_type(
42-
typ: type[NDFrame], new_axes: Sequence[Index]
43-
) -> dict[str, Index]:
44+
def _zip_axes_from_type(typ: FrameT, new_axes: Sequence[Index]) -> dict[str, Index]:
4445
return {name: new_axes[i] for i, name in enumerate(typ._AXIS_ORDERS)}
4546

4647

@@ -207,20 +208,18 @@ def is_series(obj) -> bool:
207208

208209

209210
def is_series_or_dataframe(obj) -> bool:
210-
from bigframes_vendored.pandas.core.frame import NDFrame
211+
from bigframes.pandas import DataFrame, Series
211212

212-
return isinstance(obj, NDFrame)
213+
return isinstance(obj, Series | DataFrame)
213214

214215

215216
def is_pandas_object(obj) -> bool:
216-
from bigframes_vendored.pandas.core.frame import NDFrame
217-
from bigframes_vendored.pandas.core.indexes.base import Index
217+
from bigframes.pandas import DataFrame, Index, Series
218218

219-
return isinstance(obj, NDFrame) or isinstance(obj, Index)
219+
return isinstance(obj, Series | DataFrame | Index)
220220

221221

222222
def is_pandas_type(type) -> bool:
223-
from bigframes_vendored.pandas.core.frame import NDFrame
224-
from bigframes_vendored.pandas.core.indexes.base import Index
223+
from bigframes.pandas import DataFrame, Index, Series
225224

226-
return issubclass(type, NDFrame) or issubclass(type, Index)
225+
return issubclass(type, Series | DataFrame | Index)

third_party/bigframes_vendored/pandas/core/computation/eval.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from bigframes_vendored.pandas.core.computation.expr import Expr, PARSERS
1313
from bigframes_vendored.pandas.core.computation.parsing import tokenize_string
1414
from bigframes_vendored.pandas.core.computation.scope import ensure_scope
15-
from bigframes_vendored.pandas.core.generic import NDFrame
1615
from bigframes_vendored.pandas.util._validators import validate_bool_kwarg
1716
from pandas.io.formats.printing import pprint_thing
1817

@@ -317,14 +316,16 @@ def eval(
317316

318317
# assign if needed
319318
assigner = parsed_expr.assigner
319+
from bigframes.pandas import DataFrame, Series
320+
320321
if env.target is not None and assigner is not None:
321322
target_modified = True
322323

323324
# if returning a copy, copy only on the first assignment
324325
if not inplace and first_expr:
325326
try:
326327
target = env.target
327-
if isinstance(target, NDFrame):
328+
if isinstance(target, Series | DataFrame):
328329
target = target.copy()
329330
except AttributeError as err:
330331
raise ValueError("Cannot return a copy of the target") from err
@@ -338,7 +339,7 @@ def eval(
338339
try:
339340
with warnings.catch_warnings(record=True):
340341
# TODO: Filter the warnings we actually care about here.
341-
if inplace and isinstance(target, NDFrame):
342+
if inplace and isinstance(target, Series | DataFrame):
342343
target.loc[:, assigner] = ret
343344
else:
344345
target[ # pyright: ignore[reportGeneralTypeIssues]

third_party/bigframes_vendored/pandas/core/generic.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,15 +1229,6 @@ def pipe(
12291229
"""
12301230
return common.pipe(self, func, *args, **kwargs)
12311231

1232-
def __nonzero__(self):
1233-
"""Returns the truth value of the object."""
1234-
raise ValueError(
1235-
f"The truth value of a {type(self).__name__} is ambiguous. "
1236-
"Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1237-
)
1238-
1239-
__bool__ = __nonzero__
1240-
12411232
def __getattr__(self, name: str):
12421233
"""
12431234
After regular attribute access, try looking up the name

0 commit comments

Comments
 (0)