Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -525,49 +525,55 @@ def transform_cols(df: pd.DataFrame, cols: List[str], method="log"):
|
|
| 525 |
# -----------------------------
|
| 526 |
|
| 527 |
def update_column_lists(df):
|
| 528 |
-
"""
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
return (
|
| 554 |
-
gr.
|
| 555 |
-
gr.
|
| 556 |
-
gr.
|
| 557 |
-
gr.
|
| 558 |
-
gr.
|
| 559 |
-
gr.
|
| 560 |
-
gr.
|
| 561 |
-
gr.
|
| 562 |
-
gr.
|
| 563 |
-
gr.
|
| 564 |
-
gr.
|
| 565 |
-
gr.
|
| 566 |
-
gr.
|
| 567 |
-
gr.
|
| 568 |
-
gr.
|
| 569 |
)
|
| 570 |
|
|
|
|
| 571 |
def apply_column_operations(df, selected_cols, rename_mapping, dtype_conversions):
|
| 572 |
"""Apply column selection, renaming, and type conversions"""
|
| 573 |
df = df.copy()
|
|
|
|
| 525 |
# -----------------------------
|
| 526 |
|
| 527 |
def update_column_lists(df):
|
| 528 |
+
"""
|
| 529 |
+
Return a tuple of gr.update(...) values that correspond exactly to the
|
| 530 |
+
prepare_widget_outputs order:
|
| 531 |
+
[available_cols, rename_col_old, dtype_col, num_impute_cols,
|
| 532 |
+
cat_impute_cols, replace_col, split_col, date_col_selected, pivot_index,
|
| 533 |
+
text_ops_cols, groupby_cols, agg_columns, pivot_columns, pivot_values, join_key]
|
| 534 |
+
"""
|
| 535 |
+
# safe column list getter - ensure strings, flatten MultiIndex if present
|
| 536 |
+
def get_columns_safe(df):
|
| 537 |
+
if df is None:
|
| 538 |
+
return []
|
| 539 |
+
cols = list(df.columns)
|
| 540 |
+
# handle MultiIndex columns
|
| 541 |
+
if hasattr(df.columns, "levels") and hasattr(df.columns, "names"):
|
| 542 |
+
try:
|
| 543 |
+
cols = ['_'.join(map(str, c)) if isinstance(c, (list, tuple)) else str(c) for c in cols]
|
| 544 |
+
except Exception:
|
| 545 |
+
cols = [str(c) for c in cols]
|
| 546 |
+
else:
|
| 547 |
+
cols = [str(c) for c in cols]
|
| 548 |
+
return cols
|
| 549 |
+
|
| 550 |
+
cols = get_columns_safe(df)
|
| 551 |
+
single_value = cols[0] if cols else None
|
| 552 |
+
multi_value = cols if cols else []
|
| 553 |
+
|
| 554 |
+
# Choose reasonable defaults for UI elements:
|
| 555 |
+
# - For components that expect a list/multiselect: value=multi_value
|
| 556 |
+
# - For single-select dropdowns: value=single_value
|
| 557 |
+
# NOTE: adjust ordering if your outputs wiring order differs.
|
| 558 |
return (
|
| 559 |
+
gr.update(choices=cols, value=multi_value), # available_cols (CheckboxGroup / Multiselect)
|
| 560 |
+
gr.update(choices=cols, value=single_value), # rename_col_old (Dropdown)
|
| 561 |
+
gr.update(choices=cols, value=single_value), # dtype_col (Dropdown for selecting column to change dtype)
|
| 562 |
+
gr.update(choices=cols, value=multi_value), # num_impute_cols (CheckboxGroup / Multiselect)
|
| 563 |
+
gr.update(choices=cols, value=multi_value), # cat_impute_cols (CheckboxGroup / Multiselect)
|
| 564 |
+
gr.update(choices=cols, value=multi_value), # replace_col (CheckboxGroup / Multiselect)
|
| 565 |
+
gr.update(choices=cols, value=multi_value), # split_col (CheckboxGroup / Multiselect)
|
| 566 |
+
gr.update(choices=cols, value=single_value), # date_col_selected (Dropdown)
|
| 567 |
+
gr.update(choices=cols, value=single_value), # pivot_index (Dropdown)
|
| 568 |
+
gr.update(choices=cols, value=multi_value), # text_ops_cols (CheckboxGroup / Multiselect)
|
| 569 |
+
gr.update(choices=cols, value=multi_value), # groupby_cols (CheckboxGroup / Multiselect)
|
| 570 |
+
gr.update(choices=cols, value=multi_value), # agg_columns (CheckboxGroup / Multiselect)
|
| 571 |
+
gr.update(choices=cols, value=multi_value), # pivot_columns (CheckboxGroup / Multiselect)
|
| 572 |
+
gr.update(choices=cols, value=multi_value), # pivot_values (CheckboxGroup / Multiselect)
|
| 573 |
+
gr.update(choices=cols, value=single_value) # join_key (Dropdown)
|
| 574 |
)
|
| 575 |
|
| 576 |
+
|
| 577 |
def apply_column_operations(df, selected_cols, rename_mapping, dtype_conversions):
|
| 578 |
"""Apply column selection, renaming, and type conversions"""
|
| 579 |
df = df.copy()
|