CarlyneB commited on
Commit
910dded
·
1 Parent(s): 4ac6bf0

[FIX] The DataFrame is empty when no CDR method is selected.

Browse files
Files changed (1) hide show
  1. tabs/tab1_inputs.py +30 -15
tabs/tab1_inputs.py CHANGED
@@ -289,8 +289,8 @@ def dialog_add_custom_resource(cost_sliders, edit_index: int | None = None, pres
289
  errors.append(f"**{batch_name}** already exists. Choose a different name.")
290
  if not batch_amount or batch_amount <= 0:
291
  errors.append("Available amount must be greater than 0.")
292
- # if not method_configs:
293
- # errors.append("Select at least one CDR method.")
294
  for m, c in method_configs.items():
295
  if any(v is None for v in [c["min"], c["median"], c["max"]]):
296
  errors.append(f"**{m}**: all coefficient fields (min, median, max) are required.")
@@ -496,18 +496,33 @@ def render_custom_batch_inline(global_idx, batch, cost_sliders, unit):
496
  }
497
  for m, c in batch["methods"].items()
498
  ]
499
- st.dataframe(
500
- pd.DataFrame(rows),
501
- width='stretch',
502
- hide_index=True,
503
- key=f"batch_editor_{global_idx}",
504
- column_config={
505
- "Method": st.column_config.TextColumn(disabled=True),
506
- col_min: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
507
- col_med: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
508
- col_max: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
509
- },
510
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
  with st.container(key=f"container-button-{global_idx}"):
513
  if st.button("Delete", key=f"del_batch_{global_idx}",
@@ -720,7 +735,7 @@ def render_tab(cost_sliders):
720
 
721
  if secondary_for_r:
722
  st.caption(
723
- "Secondary methods that can be added in the **Resource Coefficient** tab:\n\n"
724
  + "\n".join(f"- {m}" for m in secondary_for_r)
725
  )
726
 
 
289
  errors.append(f"**{batch_name}** already exists. Choose a different name.")
290
  if not batch_amount or batch_amount <= 0:
291
  errors.append("Available amount must be greater than 0.")
292
+ if not method_configs and not secondary_related:
293
+ errors.append("Select at least one CDR method.")
294
  for m, c in method_configs.items():
295
  if any(v is None for v in [c["min"], c["median"], c["max"]]):
296
  errors.append(f"**{m}**: all coefficient fields (min, median, max) are required.")
 
496
  }
497
  for m, c in batch["methods"].items()
498
  ]
499
+ if rows:
500
+ st.dataframe(
501
+ pd.DataFrame(rows),
502
+ width='stretch',
503
+ hide_index=True,
504
+ key=f"batch_editor_{global_idx}",
505
+ column_config={
506
+ "Method": st.column_config.TextColumn(disabled=True),
507
+ col_min: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
508
+ col_med: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
509
+ col_max: st.column_config.NumberColumn(format="%.4f", min_value=0.0),
510
+ },
511
+ )
512
+ else:
513
+ secondary_methods = [
514
+ m for m in cost_sliders
515
+ if (m, batch["group"]) in secondary_resources
516
+ ]
517
+ if secondary_methods:
518
+ methods_list = ", ".join(f"**{m}**" for m in secondary_methods)
519
+ st.caption(
520
+ f"*No CDR methods selected.*\n\n"
521
+ f"This resource is available as an optional input for: {methods_list}.\n\n"
522
+ f"Go to the **Resource Coefficients** tab to enable this resource for any of the methods above."
523
+ )
524
+ else:
525
+ st.caption("No CDR methods selected.")
526
 
527
  with st.container(key=f"container-button-{global_idx}"):
528
  if st.button("Delete", key=f"del_batch_{global_idx}",
 
735
 
736
  if secondary_for_r:
737
  st.caption(
738
+ "The following methods use this resource as secondary and may be assigned later in the **Resource Coefficients** tab:\n\n"
739
  + "\n".join(f"- {m}" for m in secondary_for_r)
740
  )
741