Skip to content

Commit f271962

Browse files
authored
feat: Display custom single index column in anywidget mode (#2311)
This PR introduces the single column display for anywidget mode. A screenshot of single index column display is here: screen/6VLA4Nk68TsYczV Fixes #<459515995> 🦕
1 parent 80dbc2d commit f271962

File tree

3 files changed

+260
-116
lines changed

3 files changed

+260
-116
lines changed

bigframes/display/anywidget.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _cached_data(self) -> pd.DataFrame:
245245
"""Combine all cached batches into a single DataFrame."""
246246
if not self._cached_batches:
247247
return pd.DataFrame(columns=self._dataframe.columns)
248-
return pd.concat(self._cached_batches, ignore_index=True)
248+
return pd.concat(self._cached_batches)
249249

250250
def _reset_batch_cache(self) -> None:
251251
"""Resets batch caching attributes."""
@@ -294,8 +294,18 @@ def _set_table_html(self) -> None:
294294
break
295295

296296
# Get the data for the current page
297-
page_data = cached_data.iloc[start:end]
298-
297+
page_data = cached_data.iloc[start:end].copy()
298+
299+
# Handle index display
300+
# TODO(b/438181139): Add tests for custom multiindex
301+
if self._dataframe._block.has_index:
302+
index_name = page_data.index.name
303+
page_data.insert(
304+
0, index_name if index_name is not None else "", page_data.index
305+
)
306+
else:
307+
# Default index - include as "Row" column
308+
page_data.insert(0, "Row", range(start + 1, start + len(page_data) + 1))
299309
# Handle case where user navigated beyond available data with unknown row count
300310
is_unknown_count = self.row_count is None
301311
is_beyond_data = self._all_data_loaded and len(page_data) == 0 and self.page > 0

0 commit comments

Comments
 (0)