Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bigframes/_config/display_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DisplayOptions:
progress_bar: Optional[str] = "auto"
repr_mode: Literal["head", "deferred", "anywidget"] = "head"

max_colwidth: Optional[int] = 50
max_info_columns: int = 100
max_info_rows: Optional[int] = 200000
memory_usage: bool = True
Expand All @@ -52,6 +53,8 @@ def pandas_repr(display_options: DisplayOptions):
so that we don't override pandas behavior.
"""
with pd.option_context(
"display.max_colwidth",
display_options.max_colwidth,
"display.max_columns",
display_options.max_columns,
"display.max_rows",
Expand Down
24 changes: 24 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,30 @@ def test_join_repr(scalars_dfs_maybe_ordered):
assert actual == expected


def test_repr_w_display_options(scalars_dfs, session):
metrics = session._metrics
scalars_df, _ = scalars_dfs
# get a pandas df of the expected format
df, _ = scalars_df._block.to_pandas()
pandas_df = df.set_axis(scalars_df._block.column_labels, axis=1)
pandas_df.index.name = scalars_df.index.name

executions_pre = metrics.execution_count
with bigframes.option_context(
"display.max_rows", 10, "display.max_columns", 5, "display.max_colwidth", 10
):

# When there are 10 or fewer rows, the outputs should be identical except for the extra note.
actual = scalars_df.head(10).__repr__()
executions_post = metrics.execution_count

with display_options.pandas_repr(bigframes.options.display):
pandas_repr = pandas_df.head(10).__repr__()

assert actual == pandas_repr
assert (executions_post - executions_pre) <= 3


def test_repr_html_w_all_rows(scalars_dfs, session):
metrics = session._metrics
scalars_df, _ = scalars_dfs
Expand Down