Skip to content

Commit 42da847

Browse files
committed
Revert "add todo and revert change"
This reverts commit 153e1d2.
1 parent 9f13d6e commit 42da847

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

bigframes/dataframe.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import re
2424
import sys
2525
import textwrap
26-
import traceback
2726
import typing
2827
from typing import (
2928
Any,
@@ -783,9 +782,9 @@ def __repr__(self) -> str:
783782

784783
opts = bigframes.options.display
785784
max_results = opts.max_rows
786-
# anywdiget mode uses the same display logic as the "deferred" mode
787-
# for faster execution
788-
if opts.repr_mode in ("deferred", "anywidget"):
785+
786+
# Only deferred mode shows dry run
787+
if opts.repr_mode in ("deferred"):
789788
return formatter.repr_query_job(self._compute_dry_run())
790789

791790
# TODO(swast): pass max_columns and get the true column count back. Maybe
@@ -851,27 +850,27 @@ def _repr_html_(self) -> str:
851850

852851
if opts.repr_mode == "anywidget":
853852
try:
853+
import anywidget # noqa: F401
854854
from IPython.display import display as ipython_display
855+
import traitlets # noqa: F401
855856

856857
from bigframes import display
857-
858-
# Always create a new widget instance for each display call
859-
# This ensures that each cell gets its own widget and prevents
860-
# unintended sharing between cells
861-
widget = display.TableWidget(df.copy())
862-
863-
ipython_display(widget)
864-
return "" # Return empty string since we used display()
865-
866-
except (AttributeError, ValueError, ImportError):
867-
# Fallback if anywidget is not available
858+
except ImportError:
868859
warnings.warn(
869-
"Anywidget mode is not available. "
860+
"anywidget or its dependencies are not installed. "
870861
"Please `pip install anywidget traitlets` or `pip install 'bigframes[anywidget]'` to use interactive tables. "
871-
f"Falling back to deferred mode. Error: {traceback.format_exc()}"
862+
"Falling back to deferred mode."
872863
)
873864
return formatter.repr_query_job(self._compute_dry_run())
874865

866+
# Always create a new widget instance for each display call
867+
# This ensures that each cell gets its own widget and prevents
868+
# unintended sharing between cells
869+
widget = display.TableWidget(df.copy())
870+
871+
ipython_display(widget)
872+
return "" # Return empty string since we used display()
873+
875874
# Continue with regular HTML rendering for non-anywidget modes
876875
# TODO(swast): pass max_columns and get the true column count back. Maybe
877876
# get 1 more column than we have requested so that pandas can add the
@@ -2564,25 +2563,33 @@ def sort_index(
25642563
) -> None:
25652564
...
25662565

2567-
@validations.requires_index
25682566
def sort_index(
25692567
self,
25702568
*,
2569+
axis: Union[int, str] = 0,
25712570
ascending: bool = True,
25722571
inplace: bool = False,
25732572
na_position: Literal["first", "last"] = "last",
25742573
) -> Optional[DataFrame]:
2575-
if na_position not in ["first", "last"]:
2576-
raise ValueError("Param na_position must be one of 'first' or 'last'")
2577-
na_last = na_position == "last"
2578-
index_columns = self._block.index_columns
2579-
ordering = [
2580-
order.ascending_over(column, na_last)
2581-
if ascending
2582-
else order.descending_over(column, na_last)
2583-
for column in index_columns
2584-
]
2585-
block = self._block.order_by(ordering)
2574+
if utils.get_axis_number(axis) == 0:
2575+
if na_position not in ["first", "last"]:
2576+
raise ValueError("Param na_position must be one of 'first' or 'last'")
2577+
na_last = na_position == "last"
2578+
index_columns = self._block.index_columns
2579+
ordering = [
2580+
order.ascending_over(column, na_last)
2581+
if ascending
2582+
else order.descending_over(column, na_last)
2583+
for column in index_columns
2584+
]
2585+
block = self._block.order_by(ordering)
2586+
else: # axis=1
2587+
_, indexer = self.columns.sort_values(
2588+
return_indexer=True, ascending=ascending, na_position=na_position # type: ignore
2589+
)
2590+
block = self._block.select_columns(
2591+
[self._block.value_columns[i] for i in indexer]
2592+
)
25862593
if inplace:
25872594
self._set_block(block)
25882595
return None

bigframes/display/anywidget.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ def _reset_batches_for_new_page_size(self):
191191

192192
def _set_table_html(self):
193193
"""Sets the current html data based on the current page and page size."""
194-
# TODO (shuowei): BigFrames Series with db_dtypes.JSONArrowType column
195-
# fails to convert to pandas DataFrame in anywidget environment due to
196-
# missing handling in to_pandas_batches(). b/453561268
197194
# For empty dataframe, render empty table with headers.
198195
if self.row_count == 0:
199196
page_data = self._cached_data

0 commit comments

Comments
 (0)