Bugfix/cli max rows (#6374)

* fix: cli max rows

* fix: settings menu

---------

Co-authored-by: Henrique Joaquim <henriquecjoaquim@gmail.com>
This commit is contained in:
montezdesousa
2024-05-07 18:12:58 +01:00
committed by GitHub
parent 5777d090f1
commit 712ccbc1c6
5 changed files with 19 additions and 20 deletions

View File

@@ -454,6 +454,9 @@ def print_rich_table( # noqa: PLR0912
if export:
return
MAX_COLS = Session().settings.ALLOWED_NUMBER_OF_COLUMNS
MAX_ROWS = Session().settings.ALLOWED_NUMBER_OF_ROWS
# Make a copy of the dataframe to avoid SettingWithCopyWarning
df = df.copy()
@@ -525,16 +528,12 @@ def print_rich_table( # noqa: PLR0912
if columns_to_auto_color is None and rows_to_auto_color is None:
df = df.applymap(lambda x: return_colored_value(str(x)))
exceeds_allowed_columns = (
len(df.columns) > Session().settings.ALLOWED_NUMBER_OF_COLUMNS
)
exceeds_allowed_rows = len(df) > Session().settings.ALLOWED_NUMBER_OF_ROWS
exceeds_allowed_columns = len(df.columns) > MAX_COLS
exceeds_allowed_rows = len(df) > MAX_ROWS
if exceeds_allowed_columns:
original_columns = df.columns.tolist()
trimmed_columns = df.columns.tolist()[
: Session().settings.ALLOWED_NUMBER_OF_COLUMNS
]
trimmed_columns = df.columns.tolist()[:MAX_COLS]
df = df[trimmed_columns]
trimmed_columns = [
col for col in original_columns if col not in trimmed_columns
@@ -542,9 +541,9 @@ def print_rich_table( # noqa: PLR0912
if exceeds_allowed_rows:
n_rows = len(df.index)
trimmed_rows = df.index.tolist()[: Session().settings.ALLOWED_NUMBER_OF_ROWS]
df = df.loc[trimmed_rows]
trimmed_rows_count = n_rows - Session().settings.ALLOWED_NUMBER_OF_ROWS
max_rows = MAX_ROWS
df = df[:max_rows]
trimmed_rows_count = n_rows - max_rows
if use_tabulate_df:
table = Table(title=title, show_lines=True, show_header=show_header)