TypeError: 'key' is an invalid keyword argument for bisect_left()
Opened this issue · 0 comments
jiauy commented
python 3.9 not support this format args
def _find_leftmost_gt(sorted_list, value, key_func):
"""Find leftmost value greater than value
Therefore, finds the leftmost box where box_max > y_min
In other words, the first row where the row might intersect y_min, even a little bit
"""
i = bisect.bisect_left(sorted_list, value, key=key_func)
return i
python 3.9 vs python3.11
- python 3.9
def bisect_left(a, x, lo=0, hi=None):
"""Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e < x, and all e in
a[i:] have e >= x. So if x already appears in the list, a.insert(x) will
insert just before the leftmost x already there.
Optional args lo (default 0) and hi (default len(a)) bound the
slice of a to be searched.
"""
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
# Use __lt__ to match the logic in list.sort() and in heapq
if a[mid] < x: lo = mid+1
else: hi = mid
return lo
- python 3.11
def bisect_left(a, x, lo=0, hi=None, *, key=None):
"""Return the index where to insert item x in list a, assuming a is sorted.
The return value i is such that all e in a[:i] have e < x, and all e in
a[i:] have e >= x. So if x already appears in the list, a.insert(i, x) will
insert just before the leftmost x already there.
Optional args lo (default 0) and hi (default len(a)) bound the
slice of a to be searched.
"""
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
# Note, the comparison uses "<" to match the
# __lt__() logic in list.sort() and in heapq.
if key is None:
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
else:
while lo < hi:
mid = (lo + hi) // 2
if key(a[mid]) < x:
lo = mid + 1
else:
hi = mid
return lo
error log
Traceback (most recent call last):
File "C:\Users\liudong\AppData\Roaming\Python\Python39\site-packages\IPython\core\interactiveshell.py", line 3550, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-9-571fbe01743b>", line 1, in <module>
ft.visualize()
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function.py", line 366, in visualize
self._df = self.df()
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function.py", line 347, in df
self._df = extract_to_df(self, config=config)
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function_algorithm.py", line 777, in extract_to_df
table_array = _fill_using_partitions(table.text_positions(remove_table_offset=True), config=config,
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function_algorithm.py", line 544, in _fill_using_partitions
row_num, row_max_iob = _find_best_row_for_text(sorted_rows, textbox)
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function_algorithm.py", line 321, in _find_best_row_for_text
i = _find_leftmost_gt(sorted_rows, ymin, lambda row: row['bbox'][3])
File "E:\PythonEnvs\CancelAccount\lib\site-packages\gmft\table_function_algorithm.py", line 107, in _find_leftmost_gt
i = bisect.bisect_left(sorted_list, value, key=key_func)
TypeError: 'key' is an invalid keyword argument for bisect_left()