Skip to content

Commit 5229e07

Browse files
feat: Support display.max_colwidth option (#2053)
1 parent 873d0ee commit 5229e07

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

bigframes/_config/display_options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DisplayOptions:
3535
progress_bar: Optional[str] = "auto"
3636
repr_mode: Literal["head", "deferred", "anywidget"] = "head"
3737

38+
max_colwidth: Optional[int] = 50
3839
max_info_columns: int = 100
3940
max_info_rows: Optional[int] = 200000
4041
memory_usage: bool = True
@@ -52,6 +53,8 @@ def pandas_repr(display_options: DisplayOptions):
5253
so that we don't override pandas behavior.
5354
"""
5455
with pd.option_context(
56+
"display.max_colwidth",
57+
display_options.max_colwidth,
5558
"display.max_columns",
5659
display_options.max_columns,
5760
"display.max_rows",

tests/system/small/test_dataframe.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,30 @@ def test_join_repr(scalars_dfs_maybe_ordered):
888888
assert actual == expected
889889

890890

891+
def test_repr_w_display_options(scalars_dfs, session):
892+
metrics = session._metrics
893+
scalars_df, _ = scalars_dfs
894+
# get a pandas df of the expected format
895+
df, _ = scalars_df._block.to_pandas()
896+
pandas_df = df.set_axis(scalars_df._block.column_labels, axis=1)
897+
pandas_df.index.name = scalars_df.index.name
898+
899+
executions_pre = metrics.execution_count
900+
with bigframes.option_context(
901+
"display.max_rows", 10, "display.max_columns", 5, "display.max_colwidth", 10
902+
):
903+
904+
# When there are 10 or fewer rows, the outputs should be identical except for the extra note.
905+
actual = scalars_df.head(10).__repr__()
906+
executions_post = metrics.execution_count
907+
908+
with display_options.pandas_repr(bigframes.options.display):
909+
pandas_repr = pandas_df.head(10).__repr__()
910+
911+
assert actual == pandas_repr
912+
assert (executions_post - executions_pre) <= 3
913+
914+
891915
def test_repr_html_w_all_rows(scalars_dfs, session):
892916
metrics = session._metrics
893917
scalars_df, _ = scalars_dfs

0 commit comments

Comments
 (0)