From ae8b400145374a81388aa7f654062422b48adffa Mon Sep 17 00:00:00 2001 From: "Martindale, Nathan" Date: Mon, 21 Aug 2023 14:13:25 -0400 Subject: [PATCH] Add ID search functionality in data manager --- icat/data.py | 41 +++++++++++++++++++------- icat/table.py | 2 +- notebooks/archive/Example3-Model.ipynb | 26 ++++++++++++++++ tests/test_datamanager.py | 9 ++++++ 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/icat/data.py b/icat/data.py index 1c575b9..7947430 100644 --- a/icat/data.py +++ b/icat/data.py @@ -82,12 +82,14 @@ def __init__( self.search_box = v.TextField( v_model="", - dense=True, - append_icon="mdi-magnify", - label="Search (use 'id:X' to search index)", - clearable=True, - clear_icon="mdi-close", - style_="padding-top: 7px", + # dense=True, + color="success", + # class_="success--text", + # append_icon="mdi-magnify", + label="Search (use 'ID:X' to search index)", + # clearable=True, + # clear_icon="mdi-close", + # style_="padding-top: 7px", ) self.search_box.on_event("keyup", self._handle_ipv_search_changed) self.search_box.on_event("click:clear", self._handle_ipv_search_cleared) @@ -113,6 +115,7 @@ def __init__( self.search_add_new_tooltip = v.Tooltip( top=True, + open_delay=500, v_slots=[ { "name": "activator", @@ -124,6 +127,7 @@ def __init__( ) self.search_add_sel_tooltip = v.Tooltip( top=True, + open_delay=500, v_slots=[ { "name": "activator", @@ -423,7 +427,7 @@ def _apply_filters(self): df = self._current_tab_filter( df, self.current_data_tab, self.sample_indices, self.selected_indices ) - df = DataManager._search_box_filter(df, self.search_value, self.text_col) + df = self._search_box_filter(df, self.search_value, self.text_col) df = self._prediction_range_filter(df) self.filtered_df = df @@ -518,8 +522,8 @@ def _set_page_contents(self, options): ) self.table.items = rows - @staticmethod def _search_box_filter( + self, df: pd.DataFrame, pattern: str, column: str, @@ -527,11 +531,28 @@ def _search_box_filter( """This function searches for a given string in code:`pattern` and applies it to the code:`column` within the code:`df`. - if the search is "id:" or "ID:", we directly search the index column instead + If the search is "ID:", we directly search the index column instead. """ - # TODO: possibly move to a utils.py if not pattern: return df + + # check for an index search + if pattern.startswith("ID:"): + requested_index = str(pattern[3:]) + if requested_index.isnumeric(): + self.search_box.label = "Search (index search mode)" + if int(requested_index) in df.index: + self.search_box.success = True + self.search_box.error = False + return df.iloc[[int(requested_index)]] + else: + self.search_box.success = False + self.search_box.error = True + return pd.DataFrame() + + self.search_box.label = "Search (use 'ID:X' to search index)" + self.search_box.success = False + self.search_box.error = False return df[df[column].str.contains(pattern, case=False)] # TODO: either make this static and add prediction col, diff --git a/icat/table.py b/icat/table.py index 326c8c9..c45c01a 100644 --- a/icat/table.py +++ b/icat/table.py @@ -143,7 +143,7 @@ def _template(self): example - +