romybeaute commited on
Commit
cb960fa
·
verified ·
1 Parent(s): 76c91ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -120,13 +120,12 @@ def _pick_text_column(df: pd.DataFrame) -> str | None:
120
 
121
 
122
  def _list_text_columns(df: pd.DataFrame) -> list[str]:
123
- """Return all columns that look text-like (object / string dtype)."""
124
- text_cols: list[str] = []
125
- for c in df.columns:
126
- s = df[c]
127
- if s.dtype == object or pd.api.types.is_string_dtype(s):
128
- text_cols.append(c)
129
- return text_cols
130
 
131
 
132
  def _set_from_env_or_secrets(key: str):
@@ -486,6 +485,12 @@ if CSV_PATH is None:
486
  @st.cache_data
487
  def get_text_columns(csv_path: str) -> list[str]:
488
  df_sample = pd.read_csv(csv_path, nrows=2000)
 
 
 
 
 
 
489
  return _list_text_columns(df_sample)
490
 
491
 
 
120
 
121
 
122
  def _list_text_columns(df: pd.DataFrame) -> list[str]:
123
+ """
124
+ Return all columns; we’ll cast the chosen one to string later.
125
+ This makes the selector work with any column name / dtype.
126
+ """
127
+ return list(df.columns)
128
+
 
129
 
130
 
131
  def _set_from_env_or_secrets(key: str):
 
485
  @st.cache_data
486
  def get_text_columns(csv_path: str) -> list[str]:
487
  df_sample = pd.read_csv(csv_path, nrows=2000)
488
+ if not text_columns:
489
+ st.error(
490
+ "No columns found in this CSV. At least one column is required."
491
+ )
492
+ st.stop()
493
+
494
  return _list_text_columns(df_sample)
495
 
496