match_mode argument work

This commit is contained in:
El Mau 2022-02-08 22:56:12 -06:00
parent d27630c7df
commit c59b1258da
3 changed files with 14 additions and 13 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,12 +28,14 @@ class ZAZFunctions(unohelper.Base, XZAZFunctions):
# The python default value not set in custom functions
# ~ print('Columns', lookup_array.Columns.Count)
# ~ print('Rows', lookup_array.Rows.Count)
source = lookup_array.DataArray
target = return_array.DataArray
index = next((i for i, v in enumerate(source) if v[0] == lookup_value), None)
if index:
if not index is None:
value = (target[index],)
# ~ horizontal = False
@ -50,18 +52,17 @@ class ZAZFunctions(unohelper.Base, XZAZFunctions):
# ~ else:
# ~ value = (return_array[index],)
# ~ if value is None:
# ~ if match_mode == -1:
# ~ index = bisect.bisect_right(source, lookup_value)
# ~ value = (return_array[index - 1],)
# ~ elif match_mode == 1:
# ~ index = bisect.bisect_left(source, lookup_value)
# ~ value = (return_array[index],)
# ~ elif match_mode == 2:
# ~ pass
if value is None:
source = tuple(map(lambda x: x[0], source))
if match_mode == -1:
index = bisect.bisect_right(source, lookup_value)
value = (target[index - 1],)
elif match_mode == 1:
index = bisect.bisect_left(source, lookup_value)
value = (target[index],)
# ~ if value is None and not if_not_found is None:
# ~ value = ((if_not_found,),)
if value is None and if_not_found:
value = ((if_not_found,),)
return value