Skip to content

Commit

Permalink
Fix double column issue when two anchors with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmCyan committed Aug 18, 2023
1 parent 64417e8 commit 0cb12b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion icat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ def __init__(

def _handle_ipv_search_add_new_btn_click(self, widget, event, data):
"""Event handler for when the add search box text to new anchor button is clicked."""
self.model.add_anchor(DictionaryAnchor(keywords=[self.search_value]))
if self.search_value != "":
self.model.add_anchor(DictionaryAnchor(keywords=[self.search_value]))
# self.search_box.v_model = ""
# self.search_value = ""

Expand Down
14 changes: 14 additions & 0 deletions icat/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ def _on_data_label(self, index: int | list[int], new_label: int | list[int]):
def _on_anchor_change(self, name: str, property: str, value: any):
"""Event handler for anchorlist."""
if property == "anchor_name":
# short-circuit if the name is the same as another anchor - if we continue with
# the code below, then two _last_anchor_names will have the same value and the
# columns in the dataframe end up the same and can't be "de-synced" in the interface.
anchor = self.anchor_list.get_anchor_by_panel_id(name)
if f"_{value}" in self.data.active_data.columns:
anchor._anchor_name_input.error = True
anchor._anchor_name_input.error_messages = (
"Another anchor is using this name."
)
return
else:
anchor._anchor_name_input.error = False
anchor._anchor_name_input.error_messages = ""

# no anchor value changes, so no need to re-featurize
col_name = f"_{self._last_anchor_names[name]}"
self.data.active_data.rename(columns={col_name: f"_{value}"}, inplace=True)
Expand Down

0 comments on commit 0cb12b0

Please sign in to comment.