From f3ce49e9748143abd2f0119410d8f119bc9aef5d Mon Sep 17 00:00:00 2001 From: Dealga McArdle <tetha.z@gmail.com> Date: Tue, 19 Jul 2022 11:32:42 +0200 Subject: [PATCH] fix for data --- nodes/list_struct/item_insert.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nodes/list_struct/item_insert.py b/nodes/list_struct/item_insert.py index 43fdd31d91..e552562289 100644 --- a/nodes/list_struct/item_insert.py +++ b/nodes/list_struct/item_insert.py @@ -105,21 +105,24 @@ def set_items(self, data, new_items, indexes): data_out = data.copy() if isinstance(data, list) else list(data) params = list_match_func[self.list_match_local]([indexes, new_items]) for ind, i in zip(*params): - if self.replace and len(data_out) > ind: - data_out.pop(ind) - data_out.insert(ind, i) + idx = ind % len(data) # translate to positive idx + if self.replace and len(data_out) > idx: + data_out.pop(idx) + data_out.insert(idx, i) return data_out + elif type(data) == np.ndarray: out_data = np.array(data) ind, items = list_match_func[self.list_match_local]([indexes, new_items]) + if self.replace: out_data[ind] = items - else: for i, item in zip(ind, items): out_data = np.concatenate([data[:i], [item], data[i:]]) return out_data + elif type(data) == str: ind, items = list_match_func[self.list_match_local]([indexes, new_items]) @@ -128,6 +131,7 @@ def set_items(self, data, new_items, indexes): for i, item in zip(ind, items): out_data = out_data[:i]+ str(item) + out_data[i+add_one:] return out_data + return None def get_(self, data, new_items, level, items, f):