Skip to content

Commit 9f684e9

Browse files
committed
logic to load dataset from search results
1 parent 8bc2619 commit 9f684e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

larray_editor/editor.py

+22
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ def search_term_filter_df(df, text):
363363
self.search_results_list.hide()
364364

365365

366+
def handle_search_item_click(self, item):
367+
# Extract all relevant text within last parentheses; BUT only need last parentheses, cf. "my country (Belgium) subject X (code)"
368+
# Assumes the (code) is always contained in last parentheses
369+
matches = re.findall(r'\(([^)]+)\)', item.text())
370+
371+
if matches:
372+
last_match = matches[-1]
373+
374+
# Use the code extracted text from the clicked item (this ought to be correct dataset code)
375+
code = last_match
376+
377+
# Use 'code' to load the dataset via eurostat_get
378+
from larray_eurostat import eurostat_get
379+
arr = eurostat_get(code, cache_dir='__array_cache__')
380+
381+
# Add loaded dataset to editor and shell
382+
editor = self.parent()
383+
new_data = editor.data.copy()
384+
new_data[code] = arr
385+
editor.update_mapping(new_data)
386+
editor.kernel.shell.user_ns[code] = arr
387+
366388

367389
def showAdvancedPopup(self):
368390
popup = AdvancedPopup(self)

0 commit comments

Comments
 (0)