Skip to content

Commit 701c05e

Browse files
committed
finish touch up
1 parent 5333686 commit 701c05e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

bigframes/display/anywidget.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from importlib import resources
1818
import functools
1919
import math
20-
from typing import Iterator, TYPE_CHECKING
20+
from typing import Any, Dict, Iterator, TYPE_CHECKING
2121
import uuid
2222

2323
import pandas as pd
@@ -49,7 +49,7 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
4949
dataframe: The Bigframes Dataframe to display in the widget.
5050
"""
5151
if not ANYWIDGET_INSTALLED:
52-
raise ValueError("Anywidget is not installed, cannot create TableWidget.")
52+
raise ImportError("Anywidget is not installed, cannot create TableWidget.")
5353

5454
super().__init__()
5555
self._dataframe = dataframe
@@ -71,7 +71,6 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
7171
# get the initial page
7272
self._set_table_html()
7373

74-
# Use functools.cached_property instead of @property for _esm
7574
@functools.cached_property
7675
def _esm(self):
7776
"""Load JavaScript code from external file."""
@@ -83,20 +82,31 @@ def _esm(self):
8382
table_html = traitlets.Unicode().tag(sync=True)
8483

8584
@traitlets.validate("page")
86-
def _validate_page(self, proposal):
87-
"""Validate and clamp page number to valid range."""
85+
def _validate_page(self, proposal: Dict[str, Any]):
86+
"""
87+
Validate and clamp the page number to a valid range.
88+
89+
Args:
90+
proposal:
91+
A dictionary from the traitlets library containing the proposed
92+
change. The new value is in proposal["value"].
93+
"""
8894
value = proposal["value"]
8995
if self.row_count == 0 or self.page_size == 0:
9096
return 0
97+
98+
# Calculate the zero-indexed maximum page number.
9199
max_page = max(0, math.ceil(self.row_count / self.page_size) - 1)
100+
101+
# Clamp the proposed value to the valid range [0, max_page].
92102
return max(0, min(value, max_page))
93103

94104
def _get_next_batch(self) -> bool:
95105
"""
96106
Gets the next batch of data from the generator and appends to cache.
97107
98108
Return:
99-
bool: True if a batch was successfully loaded, False otherwise.
109+
True if a batch was successfully loaded, False otherwise.
100110
"""
101111
if self._all_data_loaded:
102112
return False

0 commit comments

Comments
 (0)